abadonna/defold-detour/detour
Recast/Detour navigation meshes: path queries and crowd agents.
- GitHub: abadonna/defold-detour — pinned to
95ce965- This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit,
https://github.com/abadonna/defold-detour/archive/95ce965cb404cecfacd5ba1fc8115a6bb7341a85.zip— togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as detour from "detour"
- This repo publishes no releases or tags. Add a commit archive URL — for the pinned commit,
Functions
init(navmesh: string): NavMesh
Loads a navigation mesh.
Parameters
navmesh:string— The bytes of a Recast navmesh set file, such assys.load_resourcereturns.
Returns
NavMesh— The mesh.
Types
NavMesh
NavMesh.find_path(start: Vector3, finish: Vector3, straight_path_options?: number): LuaTable<number, PathPoint>
Finds a path between the points of the mesh nearest to start and
finish. When finish cannot be reached, the path ends at the
reachable point nearest to it; when no path is found, the table is empty.
Parameters
start:Vector3— Where to start from.finish:Vector3— Where to go.straight_path_options?:number— DetourdtStraightPathOptions:1adds a corner where the path crosses into another area,2where it crosses any polygon edge. Default is0.
Returns
LuaTable<number, PathPoint>— The corners of the path, in order. Read them withgetorpairs: keys start at 0, so this is not an array. 0️⃣ 0-based; passed todetourunchanged.
NavMesh.set_area_cost(costs: number[])
Sets the cost of crossing each area. The defaults are 1 for areas 0, 2
and 3, 10 for area 1, 2 for area 4 and 1.5 for area 5.
Parameters
costs:number[]— Cost per area:costs[0]is the cost of area 0.
NavMesh.set_include_flags(flags: number)
Sets the polygon flags a path may cross. The default is every flag but
0x10, which marks disabled polygons.
Parameters
flags:number— Bit mask of polygon flags.
NavMesh.create_crowd(max_agent_radius: number): Crowd
Prepares the mesh's crowd for up to 128 agents. Calling it again resets the same crowd.
Parameters
max_agent_radius:number— Radius of the largest agent the crowd will hold.
Returns
Crowd— The crowd.
NavMesh.delete()
Frees the mesh and its crowd. Neither can be used after it.
PathPoint
PathPoint.position: Vector3
Where the corner lies on the mesh.
PathPoint.area: number
Area id of the polygon the corner lies on.
PathPoint.start?: true
true on the corner the path starts from.
PathPoint.end?: true
true on the corner the path ends at.
PathPoint.offmesh?: true
true on a corner that starts an off-mesh connection.
Crowd
Crowd.add_agent(position: Vector3, radius: number, height: number, max_acceleration: number, max_speed: number, update_flags: number): number
Adds an agent at a position on the mesh.
Parameters
position:Vector3— Where the agent starts.radius:number— Radius of the agent.height:number— Height of the agent.max_acceleration:number— Largest change of velocity per second.max_speed:number— Largest speed.update_flags:number— DetourdtUpdateFlagsto steer with:1anticipate turns,2avoid obstacles,4keep apart from other agents,8optimize the path by visibility,16optimize the path by topology.
Returns
number— The agent id, or-1when the crowd already holds 128 agents. 0️⃣ 0-based; passed todetourunchanged.
Crowd.remove_agent(agent: number)
Removes an agent from the crowd.
Parameters
agent:number— Id of the agent, as {@link Crowd.add_agent} returned it. 0️⃣ 0-based; passed todetourunchanged.
Crowd.set_target(target: Vector3, agent?: number)
Sends agents toward the point of the mesh nearest to target.
Parameters
target:Vector3— Where to go.agent?:number— Id of the agent to send. When omitted, every active agent is sent. 0️⃣ 0-based; passed todetourunchanged.
Crowd.reset_target(agent?: number)
Stops agents moving toward their target.
Parameters
agent?:number— Id of the agent to stop. When omitted, every agent is stopped. 0️⃣ 0-based; passed todetourunchanged.
Crowd.update(dt: number): LuaTable<number, CrowdAgent>
Moves every agent by one step of the simulation.
Parameters
dt:number— Time step in seconds.
Returns
LuaTable<number, CrowdAgent>— The active agents, keyed by agent id. Read them withgetorpairs: keys start at 0 and skip inactive agents, so this is not an array. 0️⃣ 0-based; passed todetourunchanged.
CrowdAgent
CrowdAgent.position: Vector3
Where the agent is after the update.
CrowdAgent.velocity: Vector3
The agent's velocity after the update.
CrowdAgent.state: "walk" | "offmesh" | "invalid"
"walk" on the mesh, "offmesh" on an off-mesh connection, else "invalid".