Hi,
I have a character with a NavMeshAgent that uses said agent to move around. The blend tree forward speed variable ranges from [-2,2], where 0 is idle, 1 is walking, 2 is running. So I’ve set my agent speed to 2 when I want running behavior.
However, when stopping, because I am actually using root motion to position the character, he oversteps the position of the NavMeshAgent. This is not a problem while running because I force agent.nextPosition to be the current root position:
private void OnAnimatorMove()
{
Vector3 rootPosition = _animator.rootPosition;
rootPosition.y = _agent.nextPosition.y;
transform.position = rootPosition;
_agent.nextPosition = rootPosition;
}
But when we hit the edge of the navmesh, the agent position will remain on the NavMesh and we overshoot. See the below photo. This does not happen when stopping within the NavMesh because I force the agent position to match the character position. Only at the edges is it impossible for the agent position to follow because the character has animated past the navmesh.
I’ve tried matching the agent speed to the run state’s average speed but this doesn’t have any effect.
My question is similar to this one but the answer there doesn’t seem to solve the issue or even be directly applicable. I can’t set velocity because if did that, there would be no motion at all (the animation initially has 0 velocity itself when in the idle state). I want to drive the animation blend tree using the NavMeshAgent velocity. And even if I was able to devise a way to set the agent velocity based on the animation, that wouldn’t help the agent steering logic slow down rapidly enough.
Thanks,
– B.