The Great Fleece: Guard Animation (Made with Unity)

Adding guard walk and idle animation

Objective: Create an animator controller and add the animations for the guard movement and idle states.

Currently we have a guard who moves between some waypoints and stops, but he is static while moving.

First we have to go to the assets folder, create an animator controller, open the animator window and add the animation in this case idle and walk. Then add the animator component to the guard and assign the controller.

In the animator window we have to create two transitions, from walk to idle and from idle to walk. And add a bool parameter called walk which is going to be used for the transitions.

In the Animator we have to add the conditions for the transitions: when the walk parameter is true the guard has to start the walk animation and when it is false the guard has to start the idle animation. Also we have to remove the exit time to make the transition immediately.

In the GuardAI script I created an Animator variable to store the reference of the animator component of the guard and initialized it in the start function.

In the Update function when we check if targetReached is false (which means the guard is moving) I set the value of the walk parameter to true to start the walk animation.

In the coroutine WairBeforeMoving I set the value of the walk parameter to false to start the idle animation, once the function finish the coroutine the walk parameter is going to be true again.

And that’s it!!! We have a guard with idle and walking animations.

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