Add Sprint

For my own challenge, back when we implemented movement, I added a ‘sprint’ function if the player holds the ‘shift’ key (This looks different from the lectures as I’m using the enhanced input and required modifications):

I don’t love how the variables are managed (it’s admittedly a dirty hack, I think I could have made this much cleaner/more efficient coding/logic-wise). However, this led to needing to implement a sprinting animation in the state machine in this lecture and I wanted to share how I did that. This is the state machine itself:

Each state has a corresponding animation (just showing one for example):

And each transition is also handled (this example is the Idle->Moving transition:

This all led to the desired output of idling when not moving at all, walking when a simple move is performed, and sprinting when we’re moving faster.

Privacy & Terms