2.5D Platformer — Rolling #13

<Insert overused pun here>

I find myself enjoying rolling for no reason in videogames that have a roll animation. There’s something to the movement that’s quite cool. I felt like coding a rolling behaviour, so here I am with a new article.

What makes your roll special?

My implementation uses a Mixamo animation. You can’t compete with that!

Jokes aside, there’s probably nothing special about it except that it changes the controller’s collider to be smaller when rolling. It’s pretty common in 3D games, as crouching in some games require resizing the collider.

This article will be mostly to describe why it’s so curious to resize capsule colliders, as the actual rolling is way too simple.


To start rolling, the player will have to press an input. In this case, Left Shift.
Once the player presses the input, the state will change, it will store the direction in which the player pressed the input, it will resize the collider, and trigger the animation.

Resizing a capsule controller requires just a small workaround to one “flaw” about it. When changing the height of the controller, it doesn’t change the way you think. Instead of going from the top to the bottom, it actually expands the height from the center of the capsule collider.

It’s a small annoyance, but math doesn’t care what I think. To fix that so the collider stays grounded when resizing the collider, is just to change the controller center position.

Well, that sucks.

The animation could have Root Motion, and you wouldn’t need to code anything… But I ended up using movement through code because Mixamo. :)

Because the Roll state overrides any kind of movement, I also had to apply gravity or else the controller would float away when rolling away from the ground.

The roll ends as soon as the Roll animation ends. Using the Animator State Machine, I call the controller’s method RollEnd() to restore the controller’s collider normal size back and restore the normal movement of the controller.





Junior Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introduction to ThingHz- ESP32 based development board

Deploy ML project as Dashboard with Google Authentication

Technology Resolutions 2022

Monolithic vs. Micro-services architecture

Notion(productivity tool) for developer’s

Save money and improve performance with the Lambda power tuner UI

HTTP Request Methods and How They are Written

Data-Path Explained

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
Pablo Gómez Platón

Pablo Gómez Platón

Junior Unity Developer

More from Medium

5 Reasons Why Millenials Opt for Casual Relationships

STORE selects Liechtenstein for its Foundation Location 🇱🇮

STORE is a new layer one staking protocol at the intersection of cloud computing and Web3. STORE Governance is a checks and balances democracy. The STORE Foundation will be in Liechtenstein.


Interview with a Current Student — Meet Jeremie Gros!