I am using NavMeshAgents for my AI characters in my game and I am just implementing the animations for them at the moment. I am using the velocity property to check if they are moving or not and blending the idle, run and walk animations using that. However, I am not sure how I can then blend my turning left or right animations. Is there a way to detect if the NavMeshAgent is rotating?
If you’re using a rigidbody you can get the sqrMagnitude of the angularVelocity and check if it’s greater than 0. Otherwise you’ll need to keep track of your own angular velocity.
public bool IsRotating { get { return myRigidbody.angularVelocity.sqrMagnitude > 0.0f; } }
@jimroberts : using a navmesh agent and a non-kinematic rigidbody on the same object is not a good idea. The rigidbody will try to move the object with physics every frame, and the navmesh agent will snap it back to where it believes it should be. I had a rigidbody’s velocity.y register as minus several thousand for an object that stood still.
Basically, take the velocity vector put it into the models local space. Then use the z as a forward movement ratio and turn as the x. This is assumes that the model is aligned with forward and backwards being the z.
I normalize this and chuck it into my animation blend.