Current version: 0.9 Beta for Godot 3.2.x
Supported platforms: Windows, Linux
Others will be supported based on demand.
Godot plug&play implementation of detour library. It allows user to build multiple navmeshes from static objects (physics objects) for different agent sizes, it also features fast cached obstacles, and realtime updates on the navigation meshes.
Because Godot's implementation of recast lacks dynamic/realtime navigation mesh updates this plugin comes handy to developers that want simple yet performat way of doing navigation mesh updates.
This addon does not implement all the features of Detour/Recast library (yet), but it allows user to add or remove components to terrain which influence navigation. Current features are:
Currently it's suited for fixed size levels. It was tested on a RTS game, but should be more than capable of being used by any genre as long as the size of the level does not change.
Currently supports Linux and Windows platforms (If anyone is willing to build for OSx please contact me).
addons
folder in the root of your Godot project (if you don't have it yet)godot_project/addons/godot-navigation-lite
from the zip to your addons
folder, so you have addons/godot-navigation-lite
in your project.https://www.youtube.com/watch?v=rWFgo6M--Dc
Usage is very similar to the one in vanilla Godot. After setting up the addon, add a new node named DetourNavigation
. This is the root navigation node, and it should be the parent of all the nodes (like with regular Godot node), that you want to include in your navigation. Then click on that node, and on the top menu, you will see Navigation manager button.
Choose create navigation mesh or cached navigation mesh, if you require fast dynamic obstacles, besides the static ones.
Once you select the wanted navigation mesh, a new node will be added. Like with default godot navigation mesh, you have to select it and bake it. Once you do this, be sure to save the project (otherwise you will have to bake it again).
When it's baked, you can start your scene and call find_path function on the navigation mesh node (see documentation below). It will return an array of flags and vertices (same as Godot navigation mesh).
If you want to see the navigation mesh in game, just enable the Godot's "debug navigation" option in the debug menu (note - navigation will run slower as it has to create debug mesh every time).
A demo project is located in godot_project folder of the repository.
DetourNavigation
auto_add_remove_objects
if checked, a signal is connected, so every time a node enters it is checked whether it is collision shape and then it's added to navigation meshes based on their collision layer settings. Same goes for deleting nodes.
add_collision_shape(CollisionShape collision_shape)
Adds the collision shape to all DetourNavigationMesh
and DetourNavigationMeshCached
children, if collision shapes parent (static object) is in the layer that is covered by collision_mask
parameter in Navigation meshes.
remove_collision_shape(CollisionShape collision_shape)
Removes the collision shapes under the same conditions as add function.
add_cached_collision_shape(CollisionShape collision_shape)
Adds fast obstacle to DetourNavigationMeshCached
children if collision shapes parent (any physics object) is in the layer that is covered by dynamic_objects_collision_mask
parameter.
remove_cached_collision_shape(CollisionShape collision_shape)
Removes the collision shapes under the same conditions as add function.
DetourNavigationMesh
find_path(Vector3 start, Vector3 end)
Returns a dictionary with two arrays, first is a vector of Vector3 values that are points from start to end, second is an Array of flags which is currently not usable. If there is no possible path it returns null. If end or start is out of bounds it will return the path to the nearest point on the navmesh.
bake_navmesh()
Creates navigation mesh and saves it with all helper meshes to a scene, so the next time it's loaded fast from the scene file.
clear_navmesh()
Removes all the cached properties from the navigation mesh - cached collision shapes and navmesh itself.
save_navmesh()
It happens automatically when you bake the navmesh, but if you want to save a game (scene) and if there were changes to the navmesh, you have to manually call it.
DetourNavigationMeshCached
This class includes all methods and properties form DetourNavigationMesh
Feel free to open issues about bugs, create pull requests that fix them or add functionalities.
Setting up the addon is pretty simple - you have to follow the same tutorial as described in Godot official GDNative tutorial. Setup is the same, you have to init the cpp bindings folder and then run scons platform="windows"
or linux
if you use linux. Binaries will be compiled in addon folder that is the part of demo project. To test it run change folder to godot_project
and run godot main.tscn -e
.
cd godot-navigation-lite
git submodule update --init --recursive
godot --gdnative-generate-json-api api.json
cd godot-cpp
scons platform=<platform> generate_bindings=yes use_custom_api_file=yes custom_api_file=../api.json bits=64 target="debug"
cd ..
scons platform=<platform> # Add target="release" once you want to release it
Build also for release once you're ready by replacing the target="debug" for "release". I had to remove -g from scons file in godot-cpp (when using linux) to reduce the .so file size in linux for the release version (from 78MB to cca 4.5MB).
Godot Navigation Lite is under MIT license.
Creator: Miloš Lukić
Special thanks to @slapin, I based the navigation mesh generation logic on his implementation of Detour/Recast to Godot module. His module implementation is available on his godot branch.
And also thanks to @sheepandshepherd for helping with numerous Godot and C++ issues and bugs.