Navigation · function
nearestNavNode
The node nearest a world position, or −1 for a graph with none in reach.
Explained in Navigation.
function nearestNavNode(graph: NavGraph, x: number, y: number, z: number, maxDistance?: number): numberimport { nearestNavNode } from '@driftengine/nav';Parameters
| Parameter | Type | Description |
|---|---|---|
graph | NavGraph | |
x | number | |
y | number | |
z | number | |
maxDistance? | number |
In depth
A linear scan, and the ceiling is stated rather than discovered. A road network is hundreds
of nodes and a scan over it is microseconds; a graph of tens of thousands wants a spatial index,
and a consumer with one should keep their own and pass the answer to navSearch directly, which
is why that function takes node indices and not positions.
maxDistance is what stops an agent that has walked off the network being snapped onto the far
side of the map. Absent means the nearest node however far away it is.