How to better align navmesh with geometry

  • A* version: 5.2.2
  • Unity version: 2022.3.35f1

Is there any good way to get better results in regards to aligning the navmesh with the collected colliders when generating the navmesh at runtime. We do procedural levels and sometimes slopes end up near tile edges, which at times causes the navmesh to have a really big height level difference. This causes issues with stuff like dropping items where the player can walk, and having to raycast with really long max distances etc to make sure we pick usable positions.

Example of a polygon on the navmesh that end up with a height difference error of about 6 units (near the stair bottom)
image

When using a Recast Graph, I’ve found that working with the voxel and tile size settings can help alleviate this pretty well. However, depending on the size of your world, this may or may not be feasible. Give that a shot and let us know how it works for your specific project? If it doesn’t work we’ll see what we can find to make this work out a little better.

Hi

As @tealtxgr mentions, the tile size is a pretty good way to adjust this. Reducing the tile size will break up large triangles, and make it more closely follow the world geometry.
Note that for pathfinding purposes, the y coordinate is not particularly important (as long as it’s in the right ballpark).
The “Max Edge Length” can also be a useful setting to tweak.

1 Like

I tried using various configurations of Tile Size, Voxel Size, Max Border Edge etc. It helps to some extent. I still have issues if collider edges happen to align very close to a tile edge. Such as this case, where it causes a gap in the RecastGraph/NavMesh, which prevents traversal.

The stair is actually two prefabs, slightly overlapping. Its placed procedurally, so there is no real control where they might end up. In the case shown above. The issue appears where the collider is extremely close to the tile edge. Causing one side to get a “wrinkle”, better following the stair geometry. While the adjacent tile simplifies the polygon a bit too much.

In this case, the Voxel size is 0.15, tile size is 128, max border edge is at 20, and edge simplification set to 2.

If I reduce the numbers quite a bit to; 0.1, 64, 1 and 1 respectively. It gets better, but not perfect, and a extremely detailed NavMesh. There are still gaps that prevent navigation.

Even with super low values (0.1 max border edge length, and edge simplification set to 0), the issue persists.

Any advise or workaround is welcome.

Off the top of my head, I’m wondering if slope angle could be affecting this? But that’s just first random thoughts. Would you be able to send those prefabs/models over and I can see if I can recreate and fix this issue with settings tweaks?

I had the same thought, but its not it. In this example, the slope angle for the agent is 45 degrees, the slope of the colliders in the stairs are at 35 degrees. Step height is at 0.8 units, which is way more than necessary.

I’ll try to reproduce the issue in a smaller scenario.

… While trying to get more data, I discovered that Navmesh Cut components cause even more connection issues.

Example video where I turn a navmesh cut on/off and how it affects pathfinding

When the cut is active, its as if too many connections get removed. Causing a “hard edge” in the navmesh.

Very interesting .-.
(btw the video isn’t accessible, no viewing permissions)

Fixed permission.

Another video of the scenarion, this time in the scene view.

scene view of navmesh cut issue

Looks as if its a side-effect of the cut being really close to a tile border, but not extending over it

Maybe I’m missing the issue here, but after disabling the object I’m pretty sure you’d have to rescan the graph? The issue being that the player is walking all the way around seemingly, nothing right?

Maybe I’m missing the issue here, but after disabling the object I’m pretty sure you’d have to rescan the graph?

Isn’t the NavmeshCut supposed to cut/uncut without the need to rescan the whole graph?

The issue being that the player is walking all the way around seemingly, nothing right?

Yes. In this case the player can walk around. But we have other scenarios where the cut seem to cause a complete disconnect over a tile border. Stopping the player from actually progressing

Huh, you’re right- mine wasn’t updating in my little quick test. Let me see if I can find out why, and then I’ll see if it may relate to the issue here at all.

Goootcha, okay I’ll see what I can find on this issue…

(Looking into your other issue right now as well!)

Dont know why I didnt think of it previously. But I found a workaround by adding RecastNavmeshModifiers on select colliders, to force NavMesh seams. This seem to remove basically all issues mentioned above.

Example of the very first post without and with a modifier on the slope/stair walkable collider

It also fixed the mysterious random gap issues in inclines near max slope angle mentioned in this thread.

1 Like