Creating a Roll Player Action in Unity

Make the player able to roll

Rusben Guzman
2 min readApr 28, 2022

Objective: create a functionality to make the player roll when the user presses the left-shift key.

First we need the animation, for this project I downloaded all the animations from mixamo.com. Just go to the search bar and find the animation you are looking for. In this case I searched for “Roll”.

Now in the animation controller I added the new animation and created transitions from idle and run state. I created a trigger parameter called “Roll” to trigger the animation from the script.

In the player controller script I declared a transform variable that is used to store the final position when the roll animation finished (this variable is assigned in the inspector). Within the calculate movement function I check for the left-shift key to trigger the animation and also create 2 functions. Roll() triggers the roll animation and disables the player controller and RollCompleted() sets the new position and enables the player controller component.

Next for the roll animation I created a new behavior script. In the script I use the OnStateExit() to call the RollCompleted() function when the animation finishes.

And that’s it!!! We have a roll animation for the player.

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet