MilosLukic / Godot-Navigation-Lite

Godot plug&play implementation of detour. It allows user to have multiple navigation meshes, fast cached obstacles, and realtime navmesh changes.
Other
132 stars 12 forks source link

Godot-Navigation-Lite

Current version: 0.9 Beta for Godot 3.2.x

Supported platforms: Windows, Linux
Others will be supported based on demand.

Image not found

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.

Installation

Currently supports Linux and Windows platforms (If anyone is willing to build for OSx please contact me).

Download GodotNavigationLite

Video Tutorial

https://www.youtube.com/watch?v=rWFgo6M--Dc

Setup

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.

Image not found

Choose create navigation mesh or cached navigation mesh, if you require fast dynamic obstacles, besides the static ones.

Image not found

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).

Image not found

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).

Image not found

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).

Demo project

A demo project is located in godot_project folder of the repository.

Important notes

Documentation

Image not found

Class DetourNavigation

Class DetourNavigationMesh

Class DetourNavigationMeshCached

This class includes all methods and properties form DetourNavigationMesh

Contributing

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).

License

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.