I’ve explained how to make a character crouch in a previous article. We can use the same principle to make him (or her) sprint by setting the Max Walk Speed on our character movement. Let me show you how it works. Just like before we need:
- a Character (I’m using the First Person Character)
- an interface – not strictly necessary, but makes our life easier
- a Player Controller
Our Interface
We only need a single function in our interface, namely one called Toggle Sprint. We’ll set this up with a single boolean input called isSprinting.
The Player Controller
We’ll handle any user input action in our Player Controller. I’ve hooked up an Input Action for my logic already, aptly titled Sprint. Here’s what this logic looks like:
I’m reading out the pressed key via a Flip Flop Node. This in turn calls my interface function Toggle Sprint, passing on its Is A parameter to the is Sprinting boolean. That way we can keep track of the player’s button presses and toggle the sprint state.
The Character
The heavy lifting of toggling these states is happening in the Character itself. Here’s what it looks like:
We’ll begin with a Branch node, whose true/false outputs will either play or reverse a Timeline I’ve setup. This will interpolate between the values 0 and 1 over one second. Here’s what’s inside the timeline for completion:
The clever bit is hooking up the interpolated output value of this timeline to a Lerp Node, which in turn is responsible for changing the Max Walk Speed values from 600 (walking fast) to 1200 (sprinting) and back.
The dynamic duo strikes again! 👾