- Home /
Navh Mesh Agents teleporting to spot instead of staying on Nav Mesh
Hey there,
I'm trying to place moveable towers on a Nav Mesh (think Tower Defense, but with Rails). To prototype this idea, I've used the Tower Defense Dev Kit from Unity. Basically, I've just changed the base tower to be a moveable and selectable agent and created a Nav Mesh for enemies and Nav Mesh for Towers. That works just fine, but when placing the towers during runtime, the agents do not stay on the Nav Mesh they've been placed on, but instead teleport to a certain spot on a different Mesh that is not connected to the Mesh the towers have been placed on.
I put together a couple of screenshots to visualize the problem: https://i.imgur.com/ncHXu2J.jpg
Pic = Nav Meshes and tower placement points (blue+arrow)
Pic = Placeing first tower (works fine).
Pic = First tower in place and trying to place second tower.
Pic = The second tower teleports to another location, instead of behaving like Tower #1 which stayed in place.
I've noticed that all (additional) towers jump to that specific point where the second tower went.
I'd really appreciate any tips or hints on how to get this working! I've tried for a week now, but I'm not familiar enough with Unity to get this done, as it seems. Cheers!
Answer by tormentoarmagedoom · May 07, 2018 at 10:14 AM
Good day.
We ened to see the code is using to place the towers, but as a tip, when using navmesh system, and want to move/place something, once you instantiate the object, is recomended to:
1 - Instantiate
2- change transform.position = PositionYouWant
3- Do a NavMeshAgent.Warp = PositionYouwant
This way you make sure Unity recognise that the object you moving must be in the navmesh area.
I don't know if this solve your issue, but if not, i think is because some script is changing its posotions. Try to find why!
Bye!
Accept the answer ! :D It works for sure :D :D
Good points! It can also help if you have the Nav$$anonymous$$eshAgent disabled when instantiating, and only enable it after it was created.
Another thought, the issue might be related to the size of the Nav$$anonymous$$eshAgent, that is, too big for the navmesh area it wants to be placed on.
Good day @Harinezumi
the problem of "if you have the Nav$$anonymous$$eshAgent disabled when instantiating, and only enable it after it",
Is that sometimes (i don't know exactly why) the object moves a liottle (or a lot) when you activate the navmesh. With the Warp function, you ensure the navmeshagent capsule is placed exactly over the NavmeshArea point you selected (if it has a navmesharea, of course :D)
Good day to you too @tormentoarmagedoom ! :)
I didn't know about this, but I can imagine that that happens in practice, navmeshes can cause unexpected behaviours. Thanks for the info!
Your answer
Follow this Question
Related Questions
Trouble with Navmesh Agent and Navmesh Obstacle 0 Answers
Navigation Agent "Clipping" (Going inside) Navmesh Deadzone?... 1 Answer
Deleted component errors, yet component is still visible in inspector? 0 Answers
NavMesh Lookat causes jittery glitch in character 0 Answers
What is the difference between configuration of agent in 'Agents' tab and in 'Bake' tab Unity? 1 Answer