Player Roll Animation In Unity!

Objective: Add a rolling animation for your player and implement with inputs

This tutorial we are going to implement a roll for the player to preform when they are running and press a button. As we have done before, we are going to use an animation from Mixamo. As we have done previously; download it, insert it, set to humanoid, copy it, drag it into the animation view.

Now that you have the animation in the in the animation window you need to make transitions to and from. Since we want to implement this when we are moving, make a transition from your running animation to the rolling animation. We need a parameter to control this transition, we are going to use a trigger. Create a trigger for rolling.

We want to go from rolling to running, or standing depending on the level. So make a transition from rolling to both the running animation and the idle animation.

Use the speed parameter from before to determine where to transition to from the rolling animation.

With the animation and the transitions in place it’s now time to open the player script. If you have followed along with my tutorials you will already have a reference to the animator component. If now you will need to create that reference.

We only want to initiate the roll when the player is moving, so navigate into the method that handles the player’s movement. Since we are handling the movement with the horizontal input we need the input to not equal 0.(Meaning our player is moving) We also want to use a key input such as the left shift key.

What do we want to happen happen now is to trigger the animation clip. Using the animator component reference we created we call the trigger we created at the beginning.

Now your player will initiate the roll animation when we press left shift when we are moving.

This is good, and we could end there and be perfectly fine, however, for me I feel this is a slow roll and want to speed it up just a little. In the animation view select the roll animation and under speed, set to 1.5.

I am happy with this and together we have added a rolling function to your 2.5D platformer. Don’t be afraid to experiment with your animations and I’ll see you in the next tutorial!