Unity player animation
Objective: Animate player between idle and moving with NavMesh
Add prefab Darren_3D to the Player capsule with scale (X 1, Y 1, Z 1), and uncheck Mesh Renderer to hide capsule. Adjust the Capsule Collider to fit the model for Darren using the edit collider button then adjust the base offset, radius and height of the Nav Mesh Agent, see below.
Within the project window create an animator controller named Darren_Controller, placing it in the Animations folder. Add an Animator component to Darren_3D and assign the newly created controller as the controller for the animator component. Double click on the controller to open the animator window.
Next drag the idle and walk animations for Darren into the Animator window, shown below. Make sure the Walk animation has exit time is unchecked. Create a transition for idle to walk and walk to idle. Click + menu and add a bool parameter, naming it Walk.
Double click on idle to walk transition and under conditions select Walk and true, as shown below. When the Walk bool is true the walk animation will play. Similarly set the condition for walk to idle animation to Walk and false.
In the Player script create a private Animator _animator variable and assign it in void Start, see code below.
The Nav Mesh Agent has a bool, hasPath, that can be used to detect whether the player is moving to a destination. The Nav Mesh Agent, previously assigned to _agent variable, is checked for hasPath true within the void Update() of the Player script. Walk animation is activated while moving to a destination; otherwise, plays idle animation.
As seen below, the player now walks to new destination and is idle upon reaching that destination.
This article uses a Unity Store asset, The Great Fleece from GameDevJon.