Using Root Motion but NOT Root Rotation

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);
            }
        }

Hi

That is ca common problem when using root motion. Animations are often much more tricky to control to get a desired output, in particular because the actual action is often time delayed.

Often this comes down to the parametrization you use for your root motion and what fits your set of animations.

There is an included script called MecanimBridge which is so far not included in any example scene (I’ve had some trouble finding good models and animations with licenses that still allow me to distribute them with the package), but it shows many things that are useful for root motion. It specifically uses root motion from the mecanim script, but uses the rotation from the movement script (AIPath).

Here’s the output of an agent using the MecanimBridge script: https://arongranberg.com/temp/mecanim_controller_alpha.mp4