+3 votes

I want have navigation for my prcedurally generated terrain, is it possible somehow?

in Engine by (146 points)

Related: Check out https://github.com/godotengine/godot/issues/22767 and https://github.com/TheSHEEEP/godotdetour .

Not possible currently, but Navmesh during runtime has been merged into the 4.0 build. In the meantime you can create NavMeshes from CSGBoxes as per https://github.com/godotengine/godot/issues/22767#issuecomment-554478559

2 Answers

+4 votes
Best answer

It doesnt seem to be possible. I see the Bake Navmesh button in the editor calls this in the editor code:

EditorNavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node)

Which by the name means it's not available in exported game, and probably not even exposed to editor scripting. It uses the Recast library internally.

If you need that for your game, you have two options:
Either you generate your navmesh from geometry that you generated yourself already, and use NavigationMesh functions to construct it: https://docs.godotengine.org/en/3.1/classes/class_navigationmesh.html?highlight=NavigationMesh#methods
(don't just take your meshes directly though, it's a navmesh so it needs to be offset).

If you need the editor baker, you could do a feature request on Github, or expose it yourself by modifying the engine (it's open source after all).

by (27,660 points)
selected by

I created a simple unit that moves to mouse click on a navmesh. It works properly when the navmesh is baked in editor, but when I use the method NavigationMesh.create_from_mesh(Mesh mesh) the path I get from
Navigation.get_simple_path(Vector3 start, Vector3 end) is a 0 sized array, so it doesn't seem to work. Any idea why? Also, is there a way to see the navmesh in the running game for debugging purposes?

I just checked the other methods of NavigationMesh (none of them have description, I might add them if im sure about them and if i learn how to add descriptions :D ). So by checking them I checked and my mesh was added as navmesh, but I don't knwo why it's not working.

Ok, got it working, just had to tick "enabled" to false then back to true, so far doing it in editor after starting. But there is a problem, the pathfinding seems to only work this way with only one triangle of the mesh(which is a not subdivided plane right now for me). When I click to other tri, the unit is going to some place in first tri.

Ok the stopping of movement bug was because the script on the Unit was too simple yet, had to make it better, won't go into details, it was simple fix :D
So, the navigation was created in runtime! Now I just gotta figure out a way to offset the mesh, do you have any idea?
Also I'm gonna have to see how to create navmesh from more than one mesh. Do you know if there is a way to maybe combine meshes so I can still use a single mesh for this?

+1 vote

since this doesn't seem to be a possibility natively, you could get the navigation lite addon, you can get it directly from the engine, or here: https://github.com/MilosLukic/Godot-Navigation-Lite

by (249 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.