Character Animation in Unity

Calum Slee
2 min readAug 22, 2021

Over the last few articles we have created a point and click movement system. But our Player just slides across the floor. Let’s look at giving him some animations.

The character is already bundled with 3 separate animations: Idle, Walk, and Throw. If we use Unity’s Animator Window we can set Idle as our default state. Now when we run the game, at least our character won’t be a statue.

To access the Walk animation, we want to be able to call this from our code. When the NavMesh Agent attached to our Player is moving, we can use a bool parameter to allow the transition between animation states, and likewise when we reach our destination and need to stop walking.

We first need to use GetComponent or GetComponentInChildren depending on where the Animator is in the Hierarchy compared to the Player script. Then in our If Statement detecting our Raycast, after our SetDestination call we can access the Animator and Set the Bool to true.

For our transition back, we need to compare the distance between the Player and the Hit Point Destination where we clicked. We can use Vector3.Distance to create a float value between the two Vectors, and then detect if this value is less than 1 to Set the Bool to false.

--

--