3D Character Animations in Unity

Kyle W. Powers
Geek Culture
Published in
4 min readJun 29, 2021

This article will show how to set up a 3D character model in Unity with animations for idle, running, and jumping; if you don’t have a rigged version of your character, that is not a problem. You can see how to use Mixamo for Unity to rig your character in my previous article.

For movement, this character uses the simple Character Controller movement set up in a previous article.

Setting Up the Animator

The first thing you need to do is create an Animator Controller if we don’t already have one and assign it to the Animator component on the model. Then you can drag your animations for the character into the Animator window for the Controller.

Now, if you enter Play Mode, the animation set to the Default State will play.

Switch to Running

Next, create a Float Parameter for Speed that will control the change from Idle and Run. Then make a Transition from Idle to Run and add the Condition if Speed is greater than 0. After that, make another Transition from Run back to Idle with the Condition if Speed is less than 0.1. To make an instant transition disable Has Exit Time on each.

If you do not want the animation to change the position of the root bone, make sure to disable Apply Root Motion. Typically you don’t want it to be enabled.

To access the Speed Parameter and change the animations, you need a reference to the Animator in the Player script. Then grab the component in Start.

The horizontal input is what will determine in the run, or idle animation plays. The GetAxisRaw is not smoothed over time, so it will give you an instant animation change when used. Then you set the Float Parameter Speed to the absolute value of the horizontal input, so -1 returns as 1.

The Player now runs when there is horizontal input, but it doesn’t flip directions based on which way you move.

Flip the Player

To control the flipping of the Player, you will need to add a bool.

To flip the Player, you will change the y-axis rotation between 0 and 180 degrees. It will be 0 and not reversed when moving right (positive horizontal) and at 180 and flipped when moving left (negative horizontal).

The Player will now flip to the direction of movement.

Jumping

For controlling when the jump animation plays, you can use either a Trigger or a Bool Parameter. Using a Bool allows you to stop the animation at any point in case the Player touches the ground before the animation finishes. With a Trigger, the animation would continue until finished before switching. For the Transition back to Idle or Run, you can add another Condition for Speed to determine if it goes straight to Idle or Run animation.

So the script doesn’t set the Jump Parameter every frame; you need to add a bool to know if the Player is jumping.

If the Player is on the ground and jumping, you set the jumping bool to false and tell the Animator to switch out of the jump animation by setting the Bool Jump to false. Then when the Player presses the Space key, you change jumping to true and tell the Animator to start the jump animation by setting the Bool Jump to true.

The Player now enters and exits the Jump animations.

--

--

Kyle W. Powers
Geek Culture

Unity Developer, Software Engineer, Game Developer