Keeping NavMeshAgent in sync with the object it controls

As of Unity 5, NavMeshAgent seems to ignore the current position of the object it’s attached to, instead updating its position based on where it thinks it would be if it was the only thing controlling the object’s position by moving it directly.

alt text

(the cylinder is where NavMeshAgent thinks it is)

This is obviously unworkable for a million different reasons. What can I do about this? Is there some way to reactivate the old behavior from Unity 4 where it calculated its position based on where it actually was, or failing that, some way to set its position manually?

Hi,

You will have to use script to control the navAgent position. First disable NavAgent updateRotation and Position, then in the Update take control over NavAgent transform.

Vector3 worldDeltaPosition = pNavAgent.nextPosition - transform.position;
        if (worldDeltaPosition.magnitude > pNavAgent.radius)
        {
            pNavAgent.nextPosition = transform.position + 0.9f * worldDeltaPosition;
        }

More on controling NavAgent with script can be found here:

Hello everyone!

I have same problem in my project, so I just wondering, is anybody has a solution for this problem ? :slight_smile:

Thanks:
Zsolt