Using the Unity Animation System!

Objective: implement walking and idle animation for your player.

This tutorial is going to focus on the animator controller and using code to decide what and when animations will play.

To begin Select your player character in the project view. Right click on the character > create > animator controller.

Open the controller and drag in your animations you’ve created/acquired. For this tutorial I am using an idle animation and a walk animation.

The idle animation was dropped in first and was selected as a default because of it. You can tell its default because it is orange. Now we have our animations inside the controller we need to make a transition from the idle animation to the walk animation. Right click idle, select make transition, and left click walk.

We don’t want to always be walking so we need to make a transition back to the idle animation.

Now we need to control these transition with parameters. We are going to use a bool.

Name the bool walk and select the transitions. Under conditions hit the plus button and add the walk parameter. We want it to be true to go to walk and false to go to idle.

Make sure ‘Has Exit Time’ is off

Open the Player script and create a handle for the animator.

Now we can access the animator component and we can trigger the bool walk. To do this we need to first think of where we want to start walking. In the method that you use to make the player move you should start the animation there.

After this we need to decide when to switch back to the idle animation. The code that follows this is perfect. When the distance is less than 1 the player stops moving.

Now, whenever your character moves to a new target location his walking animation will begin and continue until he reaches his destination where the idle animation will take over. Don’t be afraid to add more animations and experiment with your code, and I’ll see you in the next tutorial!