# 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!

You gotta stop duplicating this post my man.

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:

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.

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++.

1 Like

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

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

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

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?

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