I use root motion and root rotation to control my NPCs. In most situations it works well. When they need to round a corner while running, however, I want to use A*'s desired rotation along with the animation’s root motion. I’ve not been able to accomplish this.
Getting A* to handle both motion and rotation is no problem, but it doesn’t produce the effect I’m hoping for. As far as I can tell, once “Can Move” is false, the MovementUpdate decides that the rotation speed should be far slower. The end result is the NPC will run through a wall (or two, or several) before it completes the turn.
When I have A* handle the motion and the rotation, the NPC turns rapidly enough to stay within the walls. When I use the animation’s root motion and root rotation, the NPC stays within the walls more often than not, but not consistently enough to be acceptable.
Any suggestions? The relevant code is below.
if (!_npc.navStarAgent.canMove)
{
if (_npc.useRootPosition || _npc.useRootRotation)
{
Vector3 nextPosition;
Quaternion nextRotation;
_npc.navStarAgent.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation);
if (_npc.useRootPosition)
{
nextPosition = _npc.transform.position += _npc.animator.deltaPosition;
}
if (_npc.useRootRotation)
{
nextRotation = _npc.animator.rootRotation;
}
else
{
_npc.transform.rotation = nextRotation;
}
_npc.navStarAgent.FinalizeMovement(nextPosition, nextRotation);
}
}