Navmesh Agents floating above ground

Hello everyone,

I am messing around with the native Unity navmesh + navmesh components to be able to bake it in runtime. I already figured out how to set navmesh surface and bake the navmesh from script after the level is procedurally generated. But I have an issue where navmesh agents are floating above ground.

dependablebreakablecarpenterant
Is there a way to set agents to navigate on navmesh but walk on the actual colider of ground mesh? From what I searched an option to bake height mesh would solve this but this option isn’t available for baking in runtime.
Also setting offset for navmesh agents won’t work as there are different areas where offset between ground and navmesh is from 0.1 to 0.2.
I saw that navmesh is reworked in Unity version 2022. Should I go for beta to work with better version of navmesh?

To be more specific:
I have a empty game object “ChunkGen” that generates all chunks of small island as its children. That root object has a NavMeshSurface component attached and after all the chunks are generated the function BakeNavMesh() is called to bake everything into single navmesh.


I am trying to make it work for weeks already and can not figure it out.
So if anyone could point me in the right direction I would be very glad for it.

Thanks,
Adam

That’s very unusual. FIrst of all try it with one unit.
Do you get this result with a flat plane or cube?
Is your navagent a child of a parent transform? If so then this could result in the floating.
Try building a new navagent with just capsule meshes and colliders, if they don’t have a problem then it’s in your setup of the model and all other components working together

I just use a cheap cheat.

  • Make sure the NavMeshAgent has it’s enemy or NPC as a child object.
  • Get the exact navmesh position, the value you’d normally pass to SetDestination.
  • Do a raycast down from a little higher, say a 0.5 units or so. Depends on your setup.
  • Set the enemy or NPC to this more exact height.
  • As a bonus, implement foot IK.

This does impact performance as you’ll do a raycast every frame.