Animation System with NavMesh

Matthew Clark
3 min readMay 6, 2021

--

In my game, I have set up my idle and walk animations. I will go through this process in this article.

The first step to getting your animations to play is creating an animator controller. Do this in your assets folder in the same spot you have your animations.

Drag this controller on your player to get started.

Double click the animator controller to open the animator window.

Drag your animations into this window.

If you right-click one of your animations you will be able to create a transition. Create transitions between the two animations.

Under parameters create a bool that will determine which animation should be playing. By default, it should be false to play the idle animation.

If you click the transitions you can set conditions. Add the walk parameter to the conditions and have the value true for the idle to walk transition and false for the walk to idle animation. Also, make sure that Has Exit Time is unchecked to immediately switch when the value changes.

Now we need to set this up to change the value depending on if the player is moving or not. This will be done using code in the player script.

In the player script create a reference to the animator and set the reference in the start method.

My animator was on a child object of the player

It is also best practice to null check if you are using get component.

Create a method to act as the animator control and call it in the update method.

To get this working create a bool that will be set to false by default.

In your animator controller method, you will check if the navmesh remaining distance is greater than the stopping distance. If it is the _walking bool is true and the walk animation should play. If it is not the _walking bool should be false and the idle animation should play.

The last thing in the method should be setting the bool value of the Walk parameter in the animator controller.

Now your player will switch between the animations at the correct times.

--

--

Matthew Clark
Matthew Clark

No responses yet