- Home /
Getting a navmeshagent back on a navmesh.
Hey!
So, in my game, I'm using the accelerometer to mess with gravity. When the gravity is wrong, I'm un-enabling the navmeshagent scripts on the objects, so they'll fall all over the place. But when gravity returns, the objects will have to get back up and attempt to go to their destinations again.
From what I can tell, the navmeshagents in my scene need to "reattach" to the navmesh and continue to their original destination. Do I need to perform any special function on the gameobject with the navmeshagent, or do i just have to rotate it back so that it's standing up, and give it a new destination? Just doing that doesn't seem to work.
What am I missing?
Try disabling the agent, and re-enabling it. It should be possible to use Nav$$anonymous$$esh.SamplePosition to do this (then simply moving the transform to that spot), but even that seems to have issues.
Hmm...yes, the problem seems to have disapppeared, though I didn't use SamplePosition. I can't find any clear explanation of what sampleposition does, though...can you tell me?
Answer by Catlard · Jun 15, 2012 at 06:26 AM
FIXED: The problem isn't necessarily the code, though I was able to get this working to some degree by turning the navmeshagent on and off--it's the navmesh system. It isn't built to have dynamically moving obstacles. The A* Pathfinding Project (the free version that you can find on the website) is a better, more versatile solution, if a little more difficult to use. I would advise you use that instead.