Journal 80 — Unity 2.5D Platformer Certification, Player Animations

Objective: To add Player animations for idle, running, and jumping

In the previous article, we added a 3D character to the basic platformer environment. In this article, we will add the animations using Mixamo and Unity.

Idle Animation

We can head over to Adobe Mixamo and download basic animations to apply to the character. We’ll start with an “idle” animation.

After dragging in the FBX animation to Unity, we need to make sure the Rig is set to “Humanoid”, and then select the animation file. As you see all its settings are locked, but if we press Ctrl+D to duplicate the animation, we now get access to all its settings. We can create a subfolder for Animations and move the original FBX animation to the FBX subfolder for storage. Then we can create an Animator Controller and subfolder.

Run Animation

We can now add a run animation. From Mixamo, you can find a basic run animation. Make sure to check off “In Place” for the running style so we can use the Character Controller to control the character.

We can drag in the animation FBX file like the last animation, set the Rig to “Humanoid”, and duplicate the animation so we can edit it. In the Preview window, we can add in the project model to see the running style.

Then we can drag the new run animation into the Animator window, create transitions, and create a Speed parameter, so that if speed is greater than 0, we can transition to the run animation, or when speed goes to 0, we go back to idle.

We can add the two transition requirements between idle and running, to set the speed value to at least 0.1 to change from idle to running and back to idle, and also we want to deselect “Has Exit Time”, so the animation can immediately transition.

Now we can preview this animation between idle and running.

Let’s update the code to add the animation transitions. In the Player script, we can add a reference to the Animator on the child. After doing that, we can check the horizontal input on the character controller. We can use Input.GetAxisRaw to check for horizontal input, and use this value to set the float value for the idle and run animations.

When checking the run and idle animations in game, note the position and rotation fluctuations while moving. If we turn off “Apply Root Motion”, this will correct those effects.

Jump Animation

Let’s add a jump animation now.

We can add the jump animation to Unity, make sure the Rig is Humanoid, and then duplicate the animator so it can be modified.

Then we can add a bool parameter for the jump animation, and transitions between running and idle.

Let’s update the Player script with the jump animations.

Now we can see the results.

Facing Direction

Last item we can fix in the animation is changing the player’s direction so he faces left and right correctly. We can do this by updating the transform.localEulerAngles, where when the direction.z is positive or negative, we change the facing direction.

Thank you for your time!



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
Chris Nielsen

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.