When moving a NavMeshAgent with editor's XYZ handles, what keeps it on the nav mesh?

When playing, if you move a NavMeshAgent with editor’s XYZ handles, it stays on the nav mesh.

I need to move an object to my cursor’s position, but have it constrain to the nav mesh in the same way.

If I do “transform.position = raycastHitPoint”, it takes it off the nav mesh. I tried using SetPosition with high speed/accel values, but it’s not a great way.

2 Answers

2

What about disabling the navmeshagent, then moving it using transform.position, then, then re-enabling the navmeshagent after the move is finished.

I meant that I want it to stay on the nav mesh, not leave it. I think I found the solution a second ago.

NavMeshHit navMeshHit;

if (NavMesh.SamplePosition(raycastHitPoint, out navMeshHit, 1, 1))
{
	navMeshAgent.Warp(navMeshHit.position);
}

Oh nice. I didn't know about Warp()