How to Set Up a Walk Animation in Unity

Animate the player when is moving

Rusben Guzman
2 min readNov 11, 2021

Objective: create an animator controller and a c# script to animate the player when is moving.

First make a right click in the hierarchy > create > animator controller.

Then we have to go to the animator windows and add all the animations. We have to add the idle animation first to make it the default one.

Then we have to create a transition from the idle animation to the walk animation and vice versa.

We also have to create a bool parameter that we have to use to switch between animations, add the condition to each transition and remove the exit time.

In the player script we have to declare an Animator variable to get the reference of the animator component and use the function GetComponentInChildren to get the animator (In this case the object with the component is a child of the player).

Then add an if statement to check if the nav mesh agent remaining distance is lower than the stop distance. If it is true we set the walk parameter as true and false in the opposite case. In order to set the value of the animator variable we have to use the function SetBool() and pass the name of the variable and the value.

And that’s it!!! The player is going to walk and stop.

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet