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:
- Fast adding and removing static objects (It uses tiled navigation mesh)
- Having multiple navigation meshes for agents of different sizes and with separate parameters (e.g. a navigation mesh for cars, people, vehicles that aren’t stopped by trees).
- Adding and removing very fast dynamic obstacles (cached obstacles – check tilecache implementation in detour library)
- More to come
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).
addonsfolder in the root of your Godot project (if you don’t have it yet)
- Download the addon, and copy the folder
godot_project/addons/godot-navigation-litefrom the zip to your
addonsfolder, so you have
addons/godot-navigation-litein your project.
- Go to project settings, click on Plugins tab and change the status of GodotNavigationLite to active.
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.
- Make sure no two physics bodies (that are used to generate navmesh) share the same location.
- Addon nodes like DetourNavigation, DetourNavigationMesh and CachedDetourNavigationMesh have automatically gdnative scripts added. Do not change them or you will lose functionality. Add child nodes with extra logic instead.
- Detour navigation always has to be direct parent to navigation mesh nodes and indirect parent to any of the geometries you want to use for building meshes. Navigation meshes do not have to be parents.
- Do not remove navigation mesh parameters from navigation mesh nodes
- When baking, you have to save the scene, otherwise you’ll have to bake it again next time.
- Dynamic objects will work when you start the scene, in editor they’re asleep.
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.
Adds the collision shape to all
DetourNavigationMeshCachedchildren, if collision shapes parent (static object) is in the layer that is covered by
collision_maskparameter in Navigation meshes.
Removes the collision shapes under the same conditions as add function.
add_cached_collision_shape(CollisionShape collision_shape)Adds fast obstacle to
DetourNavigationMeshCachedchildren if collision shapes parent (any physics object) is in the layer that is covered by
Removes the collision shapes under the same conditions as add function.
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.
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.
Removes all the cached properties from the navigation mesh – cached collision shapes and navmesh itself.
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.
This class includes all methods and properties form
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.
rts Selection and Movement Demo
A simple GODOT demo to test selection and move with units like in RTS games. You can also choose a formation shape for your units and some others parameters.
Set up the demo in GODOT
- Open Godot
- click on ‘import’ and choose the “project.godot” file on the project folder
- Them you have access to the project edition, press F5 to launch project !
In game inputs
- Left click :
- Drag to expand a shape to select units.
- Click on the UI to change parameter in runtime.
- Right click : Move the selected units around your cursor position.
In this demo, you can select units with some Control nodes and an Area2D. The esthetic as been customed with the theme asset. When selected, units are changing they underline color.
You can also move your units with a path finding system managed by an auto tiled Tilemap. In the ui, you can click some button to change your unit formation shape (square, circle or triangle).
Test with parameters
It is possible to change the number of unit that spawn at the begining of the demo.