Graph Pathfinder

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 position data 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.

6 Likes