Navigation · interface

NavGraph

A graph to path over: nodes somewhere in the world, edges between them, and a cost per edge.

Explained in Navigation.

interface NavGraph
import type { NavGraph } from '@driftengine/nav';

In depth

A graph rather than a navigation mesh, and that is a decision rather than a first step. A mesh is what you build when walkable space is an arbitrary region and an agent may cross it anywhere; a graph is what you build when the ways through a world are already a network — roads, corridors, rails, docking lanes, the connections between rooms. Consumers of this engine keep arriving with the second: one reported that they extract a road graph from their world already and that their agents still walk straight at the target and wedge against a wall on the way, about once every two minutes of play. A mesh would have asked them to throw that away and start from geometry.

What it costs is honest and worth saying at the top: an agent on a graph travels along edges, so it takes corners the graph has and none it does not. Open ground crossed by two nodes is crossed in one straight line. If a world's walkable space genuinely is a region, this is the wrong structure and a mesh is the row that is still open.

Structure of arrays, CSR adjacency, everything typed. The search below runs inside a frame budget against a graph a consumer may rebuild when the world changes, so nothing here holds an object per node and nothing allocates during a query.

Properties

NameTypeDescription
positionsreadonlyFloat32Arrayxyz per node, in world units.
nodeCountreadonlynumber
edgeStartreadonlyUint32ArrayCSR offsets: node i's edges are [edgeStart[i], edgeStart[i + 1]). Length nodeCount + 1.
edgeTargetreadonlyUint32ArrayThe node at the far end of each edge.
edgeCostreadonlyFloat32ArrayWhat each edge costs to traverse. Distance unless the caller said otherwise.