Navmesh
A Types.Pathfinder over Roblox's PathfindingService. One Path instance per navmesh, created
in new with the agent parameters and reused for every FindPath, so make one per agent rather
than one per plan. Never share one between agents: ComputeAsync yields, so a second agent's
plan would overwrite the waypoints the first is about to read.
Name is "Navmesh", which Ladder uses in its reasons. Blocked fires whenever the
Path instance reports its last computed path blocked, so a Navigator re-plans when a door
closes or a part moves into the way instead of waiting for the mover's stuck check.
Functions
new
Types
interface NavmeshOptions {AgentRadius: number?--
Passed to CreatePath. Default 2.
AgentHeight: number?--
Passed to CreatePath. Default 5.
AgentCanJump: boolean?--
Passed to CreatePath. Default false.
AgentCanClimb: boolean?--
Passed to CreatePath. Default false.
WaypointSpacing: number?--
Passed to CreatePath. Default 2.
Costs: {[string]: number}?--
Material and modifier costs passed to CreatePath. Default {}. The VLUXYAI_SAFE label of a SafeAreas area is always added at math.huge unless you set it yourself.
SimplifyAngle: number?--
Degrees: a waypoint whose turn is smaller than this is shaved off by Navmesh.Simplify. Default 8.
CollapseLabels: boolean?--
Run Navmesh.CollapseLabels over every path, so a PathfindingModifier volume that labels several waypoints in a row yields one labelled step, like a link. Default true.
StopBefore: number?--
Run Navmesh.StopBefore with this many studs, so the agent stops at the waypoint before a doorway instead of inside the closed door. 0 turns it off. Default 3.
Closest: number?--
Accept a ClosestNoPath result whose last waypoint is within this many horizontal studs of the goal, such as a player standing closer to a wall than the agent's radius. 0 turns it off. Default 4.
}Creates the Path instance through PathfindingService:CreatePath.
Errors
| Type | Description |
|---|---|
| "unknown option" | A key that is not in `NavmeshOptions`. |
Simplify
Navmesh.Simplify(angle: number?--
Degrees; a step turning less than this is dropped. Default 8.
) → Path--
A new path; the input is not modified.
Shaves off interior Walk steps that turn less than angle from the line through the last kept
step, so a mover walks a few long legs instead of stopping to turn at every 2-stud waypoint of
a gentle curve. Pure.
Always kept: the first and last step, every Jump or Custom step, every step with a Label, and the step immediately before a Jump (the jump origin matters). A path of two or fewer steps comes back as a copy.
CollapseLabels
Merges each run of consecutive steps that share a Label into the first of them, keeping
its position. A PathfindingModifier labels every waypoint inside its volume, and waypoints
sit a couple of studs apart, so a doorway would otherwise be two or three "Door" steps and a
handler would run at each. A run is broken by an unlabelled step or a different label. Pure.
WithSafeAreas
Navmesh.WithSafeAreas(costs: {[string]: number}) → {[string]: number}--
A copy with the SafeAreas label at math.huge, unless costs already prices it.
Why a navmesh never plans into an enabled safe area. Pure.
StopBefore
Navmesh.StopBefore(distance: number--
Studs. The step before must be at most this far from the labelled one.
) → Path--
A new path; the input is not modified.
Moves each label back onto the plain Walk step before it, when that step is within
distance, so the agent stops outside a doorway rather than walking into the closed door to
reach a waypoint inside it. The labelled step it came from becomes a plain Walk, kept so
the agent still walks through. A step after a Jump, a labelled one, or one too far away
keeps its label. Run it before Navmesh.Simplify, whose dropped waypoints would otherwise be
the ones to stop at. Pure.
EndsNear
Navmesh.EndsNear() → boolean--
true when the path's last step is within distance of goal, ignoring height.
Whether a partial path gets close enough to count. Pure.
FromWaypoints
Converts Path:GetWaypoints() output to Steps: Action is the waypoint action's name, and an
empty Label or one that is only the floor's material name becomes nil. Roblox labels every
waypoint with the material under it ("Plastic", "Grass") when no modifier or link labels
it; kept, every step of an ordinary path would share a label and Navmesh.CollapseLabels
would merge the whole path into its first step. A modifier label that happens to be a material
name is dropped with them, so name modifier regions something else. Pure; any table shaped
like a waypoint works.
FindPath
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsNavmesh.FindPath() → (string?--
On failure: the ComputeAsync error text, the PathStatus name (NoPath, ClosestNoPath, ...) or destroyed.
)Close
Navmesh.Close(seconds: number--
How long to refuse paths through it.
) → ()
The navmesh is Roblox's, so a link cannot be closed for one agent; instead, for seconds,
any path this pathfinder computes that crosses a step with the same label within a few
studs (or the same Instance) is reported as no path, closed <label> at <position>. The
Navigator calls this when a step handler returns false.
Destroy
Destroys the Path instance and the Blocked signal. FindPath after this returns
nil, "destroyed".