Creating a Roll Player Action in Unity

Make the player able to roll

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 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.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
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.