New beta version is available
The most important new feature is navmesh pathfinding support. A* for navmesh is polygon-based and very similar to, and inspired by, the recast/detour solution, but simplified.
You can check out the API documentation here:
Basic example is in the repo:
Notes
- Supports only static 2D navmeshes
- Supports the Defold buffer format, only
positiondata is required - The navmesh should be on the XZ plane, but you can use the query results however you like
- Works side by side with normal pathfinding, you can use both at the same time
Minimal Example
Usage is quite simple:
go.property("navmesh_buffer", resource.buffer("/example/assets/navmesh.buffer")) -- If you have a prebuilt navmesh as a buffer
function init(self)
-- You can build your own buffer or use a prebuilt one.
local navmesh_buffer = resource.get_buffer(self.navmesh_buffer)
-- Initialize the navmesh with cell count, spatial index and path settings.
pathfinder.navmesh_init(300, 6, 32, 32, 64, 5, 10, 500, true)
-- Set the buffer.
pathfinder.navmesh_set_buffer(navmesh_buffer)
-- Query the navmesh.
local path_size, path_status, path_status_text, path =
pathfinder.navmesh_find_path(
start_position.x, start_position.z,
goal_position.x, goal_position.z,
128, 0.0, false
)
end
I also made progress on setting up multiple navmeshes and A* pathfinding support. I am almost one big step away from full multi-pathfinding/navmesh support. This will be a breaking change.
How to generate a navmesh
This is the tricky part. I am tinkering with how to generate a navmesh in Defold, but since we cannot access model data directly, it does not seem possible for now. It might be possible using basic primitives or AABBs of the models, but this is not on my roadmap at the moment.
- Clean up your navmesh model and simplify it as much as possible in a 3D tool like Blender. I highly recommend using a single low-poly mesh. It is even better if it already contains holes for obstacles.
- You can use https://navmesh.isaacmason.com/ to generate and export your navmesh as GLB or GLTF. Also you may use CLI tool: glTF Transform / Recast NavMesh configuration
- Open the exported GLB or GLTF file in Blender.
- If you do not have the Clean Game Asset Exporter add-on by @MasterMind , install it from Clean Game Asset Exporter — Blender Extensions. More info: Clean Game Asset Exporter - blender add-on
- Export the buffer by selecting
Y-UPandVertex position. This will generate the.bufferfile for you.