Skip to Content
defold-typescript libraries
abadonna

abadonna/defold-detour/detour

Recast/Detour navigation meshes: path queries and crowd agents.

  • GitHub: abadonna/defold-detour — pinned to 95ce965
    1. 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 — to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as detour from "detour"

Functions

init(navmesh: string): NavMesh

Loads a navigation mesh.

Parameters

  • navmesh: string — The bytes of a Recast navmesh set file, such as sys.load_resource returns.

Returns

  • NavMesh — The mesh.

Types

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 — Detour dtStraightPathOptions: 1 adds a corner where the path crosses into another area, 2 where it crosses any polygon edge. Default is 0.

Returns

  • LuaTable<number, PathPoint> — The corners of the path, in order. Read them with get or pairs: keys start at 0, so this is not an array. 0️⃣ 0-based; passed to detour unchanged.

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.

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.

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.

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 — Detour dtUpdateFlags to steer with: 1 anticipate turns, 2 avoid obstacles, 4 keep apart from other agents, 8 optimize the path by visibility, 16 optimize the path by topology.

Returns

  • number — The agent id, or -1 when the crowd already holds 128 agents. 0️⃣ 0-based; passed to detour unchanged.

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 to detour unchanged.

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 to detour unchanged.

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 to detour unchanged.

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 with get or pairs: keys start at 0 and skip inactive agents, so this is not an array. 0️⃣ 0-based; passed to detour unchanged.

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

On this page