Navigation
constNavigation:object
Defined in: server/api.d.ts:7130
Queries the level’s navigation mesh on the server. The mesh includes walkable floors, bridges and stairs.
Copy the game’s Data/Levels/<level>/recast.pak to the server’s files/<level>/ directory. The server searches files/ recursively at startup. An optional mod.navmesh in server.json takes priority and can name a game install, level folder or pak file. The game data must be supplied separately. Without a mesh, ready is false and geometry queries return null or false. Points are world-space metres, Z up. Every query takes an optional options object. searchRadius and searchHeight limit how far a point may be from the mesh, across the ground and up or down: 2 metres by default, up to 64, and 4 by default, up to 128. Keep searchHeight under a storey’s height, or a point on one floor snaps to the floor above. doors picks which doors a query walks through: unlocked, the default, is how an NPC treats a door – open or shut, it goes through unless the door is locked; open only through doors that stand open; any ignores locks; none treats every doorway as a wall. Door states are read in the global world, except validatePatrol with an actor, which uses that actor’s world. A field given with the wrong type or out of range throws.
Type Declaration
Section titled “Type Declaration”activeOverlays
Section titled “activeOverlays”
readonlyactiveOverlays:string[]
Enabled overlays in activation order. Initially empty; the level starts with its base mesh.
overlays
Section titled “overlays”
readonlyoverlays:string[]
Available overlay names, sorted. Overlays contain replacement navigation data for quest states. Enabling one replaces the covered part of the mesh. Empty without a mesh.
readonlyready:boolean
Whether a mesh loaded from mod.navmesh or the server’s files/ directory. False when no usable copy is found; the server log gives the reason.
canReach()
Section titled “canReach()”canReach(
from,to,options?):boolean
Checks reachability by calling findPath.
Parameters
Section titled “Parameters”Where the walk starts; omitted components default to zero.
Where it should end; omitted components default to zero.
options?
Section titled “options?”How far to look for each end, and which doors to walk through.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”boolean
True when a complete path exists; false otherwise, including when no mesh is loaded.
closestPoint()
Section titled “closestPoint()”closestPoint(
point,options?):Vector3|null
Snaps a point to the nearest walkable surface.
Parameters
Section titled “Parameters”The point to snap; omitted components default to zero.
options?
Section titled “options?”How far to look, and which doors count.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”Vector3 | null
The nearest point within the search limits, or null when none is found or no mesh is loaded.
disableOverlay()
Section titled “disableOverlay()”disableOverlay(
name):boolean
Disables an overlay, restoring the previous enabled overlay or the base mesh in that area.
Parameters
Section titled “Parameters”string
An entry of activeOverlays.
Returns
Section titled “Returns”boolean
False for a name that is not enabled, or when part of the area could not be restored (the server log says why); the overlay is disabled either way.
enableOverlay()
Section titled “enableOverlay()”enableOverlay(
name):boolean
Enables an overlay. Where overlays overlap, the last enabled takes precedence. Subsequent queries use the updated mesh.
Parameters
Section titled “Parameters”string
An entry of overlays.
Returns
Section titled “Returns”boolean
False for a name the level does not ship, one already enabled, one whose tiles cannot be read or loaded (the server log says why), or without a mesh.
findPath()
Section titled “findPath()”findPath(
from,to,options?):NavigationPath|null
Plans a path around obstacles on the mesh. Plan when a destination changes; avoid recalculating every NPC’s path each tick.
Parameters
Section titled “Parameters”Where the walk starts; omitted components default to zero.
Where it should end; omitted components default to zero.
options?
Section titled “options?”How far to look for each end, and which doors to walk through.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”NavigationPath | null
The path, or null when an endpoint cannot be found, the query fails or no mesh is loaded. A partial path has complete: false.
floorAt()
Section titled “floorAt()”floorAt(
point,options?):number|null
Returns the height of the nearest walkable surface, including upper floors, bridges and stairs.
Parameters
Section titled “Parameters”The point to measure; omitted components default to zero. Its z estimates the floor height and selects the storey.
options?
Section titled “options?”How far to look.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”number | null
The height in metres, or null when none is found or no mesh is loaded.
randomPoint()
Section titled “randomPoint()”randomPoint(
center?,radius?,options?):Vector3|null
Returns a random walkable point reachable from center and no further from it across the ground than radius. A point drawn outside the circle is drawn again, a bounded number of times. Without a centre, samples the whole level, choosing each tile with equal probability.
Parameters
Section titled “Parameters”center?
Section titled “center?”The point to scatter around; it has to be on the mesh, and omitted components default to zero. Omitted entirely, the point can be anywhere on the level’s mesh; pass undefined for it and for radius to give options.
radius?
Section titled “radius?”number
How far from center, in metres, up to 512. Required with a centre.
options?
Section titled “options?”How far to look for center, and which doors the point may lie behind.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”Vector3 | null
The point, or null when center is off the mesh, no draw lands within radius, the query fails or no mesh is loaded.
raycast()
Section titled “raycast()”raycast(
from,to,options?):NavigationRay|null
Checks a straight line across the mesh and reports where it stops.
Parameters
Section titled “Parameters”Where the walk starts; omitted components default to zero.
Where it heads; only its x and y are used, the walk follows the surface.
options?
Section titled “options?”How far to look for from, and which doors let the walk through.
doors?
Section titled “doors?”"unlocked" | "open" | "any" | "none"
searchHeight?
Section titled “searchHeight?”number
searchRadius?
Section titled “searchRadius?”number
Returns
Section titled “Returns”NavigationRay | null
The result, or null when from is off the mesh, the query fails or no mesh is loaded.
validatePatrol()
Section titled “validatePatrol()”validatePatrol(
route,options?):object
Checks all legs, including the closing leg of a loop and reverse legs of ping-pong. Uses the patrol runner’s search budget. A single waypoint is checked against itself. Missing mesh reports available false; partial paths are incomplete. This does not start or change an actor’s order.
Parameters
Section titled “Parameters”string | PatrolRoute
A registered route or its id.
options?
Section titled “options?”Optional actor chooses door policy in its virtual world: unlocked doors for humanoids, no doorways for horses and animals.
actor?
Section titled “actor?”Returns
Section titled “Returns”object
available
Section titled “available”available:
boolean
complete
Section titled “complete”complete:
boolean
legs:
object[]