Nerd For Tech
Published in

Nerd For Tech

On a Roll! — Player Roll Animation

This article shows how to add the ability for the Player to Roll to get under obstacles. The Roll animations are from Mixamo, which was featured in a previous article.

We will change the Character Controller Collider through code when entering a roll to match the changed profile of the model and then change it back to normal after the animation.

In the Player script, we need some variables to implement the roll logic.

  1. The amount to add to the Player’s velocity when rolling.
  2. The new XYZ axis values for the Collider’s Center when rolling.
  3. The starting XYZ axis values for the Collider’s Center to return to after rolling.
  4. The new Height value for the Collider when rolling.
  5. The starting Height value for the Collider to return to after rolling.
  6. The bool to know if the Player is already rolling, to prevent jumping and rolling while rolling.

We get the starting values for the Collider’s Center and Height from the Controller in Start.

While the Player is on the ground, if the Left Shift key is pressed and not already rolling, we tell the Animator to play the roll animation, disable rolling and jumping till the roll is finished, and change the Collider’s Center and Height to the smaller profile. Then if the Player is rolling, we add or subtract the roll force from the velocity depending on which direction the Player is facing.

The last thing we need is a method that can be called to change the rolling bool to false enabling jumping and to roll again and to return the Collider’s Center and Height to the starting values.

In the Animator window for the Player, we need to add a Trigger Parameter for Roll to Transition to the rolling animation. Then after the animation has finished, we Transition back to Idle or Run animations. On the Roll animation State, we need to add a Behaviour script.

In the Behaviour script, when the rolling animation State finishes and Transitions to the next State, we grab the PlayerController script from the parent of the Animator and call the Stop Roll method on it.

The Player can now roll and move under the obstacle.




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

Best VPS Hosting Plans

Java Mutation Testing with Pitest

Exploring the Android land 🏝 #io18

Unable To Install MongoDB Locally

Understanding Frustum and Occlusion Culling in Unity3D

Redis latency 相關雜記

Video Playback issues, problems and errors on Windows 10/8/7

How joining a coding bootcamp, going to meetups, and winning a Hackathon changed my life completely

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
Kyle W. Powers

Kyle W. Powers

Unity Developer, Software Engineer, Game Developer

More from Medium

2D Mobile: Loot System

Building A Stealth Game — Helping Your Guards “See”

IK Weapon System in Unity

Quick and Easy: Alter Your Pre-Built Unity Texture Maps using Krita.