x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I make a one Directional sprint?

So I have set up a sprint feature where when I hold Left Shift, the speed changes to 600. However, I want to only make a one Directional sprint so when you are only holding the forward key (w)m you move forward, kind of like Call of Duty and Fortnite. I also want it to be able to sprint also when going left and forward. For example holding down w and a. Can someone send an example blueprint? Help is appreciated. Thanks!

Product Version: UE 4.20
Tags:
more ▼

asked Oct 30 '18 at 03:36 AM in Blueprint Scripting

avatar image

CODE REDBALLG
115 3 7 17

avatar image PixelOmen Oct 30 '18 at 05:05 AM

You gotta stop duplicating this post my man.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

alt text

Here it is. If it works, please accept the answer. If not, leave a comment to tell me what went wrong :)

capture.png (116.8 kB)
more ▼

answered Nov 03 '18 at 08:22 AM

avatar image

Kit Kat134
203 2 9 10

avatar image CODE REDBALLG Nov 07 '18 at 04:00 PM

Ok Thanks! It works now :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi there,

One way you can do this is by checking if the controlled pawn/character's current actor rotation is within a certain angle of the control rotation (aka, the rotation of where you're looking) while the sprint button is held down. If the character is rotated too far compared to the control rotation then you can set the movement speed back to the non-sprinting speed, but when it is within the desired angle then you set it to the sprinting speed. You'd probably want to do this on tick so that it's very responsive to your inputs. Also, you'd probably want to only use the Yaw value of each rotation when doing the comparison.

So it'd be something like this in blueprints: alt text For reference, left shift is my "sprint" key in this case. Sprint Speed is 600.0, Default Speed is 400.0, and Sprint Angle is 45.0 degrees. The sprint angle is the most important variable in this case as it is what determines when you are sprinting "forward" or not.

Also, if you'd like to have a smoother interpolation between the default and sprint speeds you can add the following code to the function. alt text Please note that 1) I'm using the "Delta Seconds" pin from the Event Tick function for the "Delta Time" of the FInterpTo functions, 2) that Interp Speed is a new variable I created that helps determine how slowly/quickly the interpolation occurs (I went with a value of 10.0 by default), and 3) this won't smoothly speed up or slow down your character unless the sprint key is down so you may need to play around with it to get the desired outcome you want.

Hopefully this helps you achieve what you're going for, or at the very least gets you thinking about how you can achieve it. With this setup though you should also be able to set up other "zones" where the speeds are different (maybe making the character move even slower than default while running backward?).

On a side note, a potentially better way to do this in C++ would be to create a custom character movement component and override the GetMaxSpeed function to include this calculation since it's already being executed every tick. But don't worry about that if you don't know or have access to C++.

capture.png (330.0 kB)
capture2.png (262.5 kB)
more ▼

answered Oct 30 '18 at 05:33 AM

avatar image

poplockentaco
239 21 12 28

avatar image CODE REDBALLG Oct 30 '18 at 02:24 PM

Thanks for the help! I will try that later today.

avatar image CODE REDBALLG Nov 01 '18 at 12:22 AM

Hello! I out in your exact same code and it doesn’t seem to be working. I entered in the correct values. When I hold left shift, it sprints, then when I let go, it keeps sprinting. What should I do?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Easier way is to just set a bool (e.g. "bForwardPressed") true when the w key is pressed (can be done with event W key pressed). When sprint button is held, only set sprint true if bForwardPressed is true. If you need an example blueprint just comment below. Im more than happy to make one

more ▼

answered Oct 30 '18 at 09:58 AM

avatar image

Kit Kat134
203 2 9 10

avatar image CODE REDBALLG Oct 30 '18 at 02:24 PM

Hello! Thank you for your help. If you can send me an example that would be nice!

avatar image Kit Kat134 Nov 03 '18 at 05:53 AM

Sorry for the wait, I'll do that now. (I didn't have access to my laptop for 4 days)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question