Manually make and set 3D navigation Mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LukeDassonville

Hello -

I recently changed my top down game from 2d to 3d, which went pretty smoothly as nearly all the code could stay the same. The one exception to this is the navigation. When it was in 2d, I made a script to update the navigation polygon whenever a new thing that needed to be avoided was added. The script was fast, and worked pretty well.

I would like to be able to use this same script, or something similar, to update the 3d navmesh as well, but I wasn’t able to find any way to do this. I did find a way to turn a navigation polygon into a navmesh with get_mesh(), but was unsuccessful at actually using the resulting mesh.

Is it possible to manually make and set a navigation mesh?


Update - I have been able to set the navmesh with either add_polygon or create_from_mesh. However, I am still having problems with both of these methods. The first is that the navigation Agent seems to get stuck on some of the edges between triangles, and the second is that the navmesh doesn’t show in game even if the show_navigation debug option is turned on.

LukeDassonville | 2022-11-03 05:03

:bust_in_silhouette: Reply From: smix8

NavigationAgent get stuck on edges when the desired distances are set to small compared to the agent speed. In that case the agent always overshoots the next path point (which is on the edge) and dances back and forth.

If you only change the internals of a NavigationMesh the debug display will not update. You need to use set_navigation_mesh() with a different NavigationMesh or set it to null first before readding the changed NavigationMesh.