2.5D Platformer — #13 Rolling

In this article, we will give the player the ability to roll under obstacles.

Head over to www.mixamo.com, search for a “roll” animation. Pick an animation that has the In Place option. This allows us to control the movement forward with the character controller.

Click the download button, choose FBX for Unity with Skin.

Once download, drag the file to your animations folder. Set the Animation Type to Humanoid and press Apply. In the Project View, expand the asset and duplicate the animation and drag it out.

Select the duplicated animation and set the Root Transform Rotation, Root Transform Position (Y), and Root Transform Position (XZ) Bake Into Pose for all three.

With the Player selected, in the Animator window, Create a Trigger called Roll. Drag on the animation into the Animator window. Make a transition with no Has Exit Time or Fixed Duration and with a condition of Roll.

We want the animation to transition to the idle animation. Make a transition from the new Animation to Idle.

In the Input Manager, I chose to duplicate the Fire1 so to make use of the LEFT CTRL. I renamed the new input to Roll and removed the mouse 0.

Remember to Save your Project whenever you make changes to any of the project settings. CTRL S does only save the scene, you need to go to File > Save Project. In the Player controller script, we want to look out for when the LEFT CTRL is pressed and call the animator trigger that we need Roll.

If we were to test it out, our roll is working but we halt just before the wall. We need to reduce the height of the character controller so it doesn’t collide with the obstacle. We will need to do this in code.

I changed the code to call a coroutine so that I can reduce the height and centre for a certain length of time and then return it back to normal.

We have now given the player the ability to roll under obstacles. Great work!

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.

--

--

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
Jean-Noel Seneque

Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com