Disable backwards sprinting

I have set up a sprinting action while moving and pressing shift.
I set up a branch to check if the player is not moving backwards and if he is moving at all.
this works until i sprint forward (w and shift), then release the move key, while still holding the shift key, now if i move backwards i still sprint. how can i disable this? so that if shift is still pressed after running, the sprint ability gets disabled or checks again if i’m moving backwards?

do i have to split the movement into forward and backward? because the branch that checks if i move backwards when pressing shift the first time doesn’t check again if i’m still holding the shift key.

hope this isn’t too confusing.

Hi there,

Because the Booleans are not being checked until keypresses, I would suggest using a gate. Have the gate run on a tick event and use the key presses to open and close the gate. Make the gate open event check those Booleans instead so they stay current and can be applied correctly at all times.

Hi NukePie,
thanks for the answer, that seems to be exactly what i need.
could u maybe elaborate on the setup? i tried the whole day to wrap my head around the correct setting, but i just can’t figure it out. still new to this and never used a gate and the epic documentation on that is fairly short.
have a nice evening…

hey Anaklosmos,

thanks for the reply. thing is, i already have a branch set up that checks, if i’m not moving backwards, when i press the sprint key.


but if i walk forward then hold the sprint key, release the forward key while still holding the sprint key and then press the backwards key, sprinting is still enabled, because it doesn’t check the bool again, as long as the sprint key is pressed.

so i would need a gate that checks if i move forward and/or sideways, and if not “closes” the ability to sprint, even if the sprint key is still pressed. i just haven’t figured out the way to properly use a gate like that.

as i couldn’t really figure the gate thing out, i found two other solutions.

the easiest one was to just add a branch to the forward/backward movement axis that checks that axis is >=0 (which means the player is moving forward and/or sideways) and if the sprint key is being pressed, then set max walk speed to a sprint speed variable, if the input axis would be smaller (which means he is moving backwards) set the walk speed to a walking speed variable. this works as intended.

the second solution uses an enum (that has three different walking states in it: walking / running / crouching ) on an event tick. the event tick goes through branches that check if the player is moving forward or backward, pressing the sprint key or is crouching, stuff like that, and then sets the enum accordingly, going into a switch for the enum, that then sets the walking speed based on the enum. this also works nicely.

now i only have to figure out, how to add my timeline to it, that eases the walk speed in an out of sprinting, cause right now it only switches between walk and sprint speed.

in terms of performance, i don’t know what to prefer, i like the enum but it’s running on the tick, so wouldn’t that be more intense on the performance, as opposed to using branches on the axis which already checks every frame.
anyone got an idea?

Very Simple Way

1 Like

here is the simple way I apologise for my poor editing skills