Resetting Run Back To Walk -- Use Flip Flop Or ...?

Hello everyone! I’m a relative newbie at using UE4, but I have figured a few things out on my own without any issue. However, I keep coming back to one problem that continuously bothers me. Here’s what it is …

I have an Input Action Event for Run using the Left Shift key. When I toggle the Left Shift key, it allows my third person character to move from a walk speed to a run speed. And when I toggle the Left Shift key again, I can go back to my walk speed. I’m okay with this setup, but I want to try something different that will reset the run back to a walk without toggling the Left Shift key again. Can I reset the Flip Flop in some way, and if so, how? Or can I make a function where if my keyboard doesn’t get any input to both the WASD keys and mouse [meaning the third person character stops completely], then the run speed returns to the walk speed? If this is possible, how can I try this? I haven’t seen many discussions about this on here, and the few that I saw mentioned using Bools or Event Ticks. I’m okay with Bools, but want to avoid Event Ticks.

Thanks in advance!

This is an image of my current set up, using a flip flop connected to two functions [StartRun and StopRun].

Like this:

It uses a gate, which is basically a reset-able flip flop. When the player starts running, it starts a timer, which checks every .25 seconds if the player has stopped running. If so, reset the gate.

PS: It is easier with tick, and the tick will only run while the player is running…

As an alternative method that does not require any timers, the method I’m presenting here tracks and accounts for any movement inputs.

By using a Bool(IsRunning?) to track the players run state, its much easier to combine the toggle option for the player and enable/disable based on other conditions; did the player stop moving completely, did they explode and get knocked over, etc.

As movement keys are released we check if it was the last one, a value of 0 on an int counts as a false for branch/if nodes.

Important Notes:
Movement Keys array has 4 hard-coded entries for this; W,A,S,D - we are testing if a pressed key is one of these or not, if it is we increment the int NumberOfInputs up, and if its released we decrement it.

I’m weary of using ticks because of performance issues. But you are right – it will only work while the player is running. I just don’t want my project to slow because of it.

I got it to work with my keyboard! WOOHOO, thank you!

Now here is a follow up question – can this same structure be applied to a gamepad controller? I added the gamepad left thumbstick button to the movement keys array, and when I tried moving with a Microsoft/XO remote, I stayed stuck in the walk position [I can run if I hold the thumbstick down, but once I let up, it goes back to walking].

Joystick values can be potentially a little trickier to deal with, but I added and tested the NumberOfInput values using a xbox one controller and it seems to behave properly (counts up and down between 0 and 2). if its staying in walk, then it might be a missing button on the gamepad to start running. the setup above only ENTERS run when you press left shift, and EXITS when either left shift is pressed again, or you begin pressing movement buttons and then stop. so just moving using the gamepads left thumbstick wont inherently enter a run mode. You would need to add a gamepad button (like B or Y or something) to the InputAction Run in the project settings.

Thank you very much! I got it working on the gamepad now =)

That’s not a tick. Tick is fine is used sparingly.

what i have to type for the nodes in the branch condition? cant get the velocity part.

1 Like

It only works if you drag from the character movement node. Then you can search for velocity :slight_smile:

For the node next to that, just drag from velocity ( which is a vector ) and type =