Nav
Queries the navmesh, the walkable surface NPCs path over. No NPC is needed.
public static class Nav
Namespace: DeadworksManaged.Api
Source: Nav.cs#L173
Notes
The navmesh is built per hull (body size), so an area one hull can cross may not exist for another. Heroes use hull 0, lane troopers hull 1. Unknown hulls fall back to 0. On a map without a navmesh every query returns null.
Fields
Nav.MaxPathPoints
The most waypoints a path can have.
Signature
public const int MaxPathPoints = 256;
Source: Nav.cs#L177
Methods
Nav.GetNearestPoint()
Returns the closest navmesh point to position, or null if none is in range.
Signature
public static Vector3? GetNearestPoint(Vector3 position, float maxDistance = 10000f, int hull = 0)
public static Vector3? GetNearestPoint(Vector3 position, CBaseEntity walker, float maxDistance = 10000f)
Parameters
position: Point to snap.maxDistance: Search radius.hull: Navmesh hull.
Source: Nav.cs#L196, Nav.cs#L205
Nav.GetArea()
Returns the nav area nearest position, or null if none is in range.
Signature
public static NavArea? GetArea(Vector3 position, float maxDistance = 200f, int hull = 0)
Source: Nav.cs#L209
Nav.GetGroundHeight()
Returns the navmesh height below position, or null if no area is in range.
Signature
public static float? GetGroundHeight(Vector3 position, float maxDistance = 1000f, int hull = 0)
Notes Uses the nearest area in 3D: a point at bridge height gets the bridge, not the ground under it.
Source: Nav.cs#L220
Nav.Raycast()
Traces a straight line across the navmesh. Returns true if it reaches end without leaving the walkable surface.
Signature
public static bool Raycast(Vector3 start, Vector3 end, out Vector3 stoppedAt, int hull = 0)
Parameters
start: Start point. Snapped onto the navmesh first.end: End point.stoppedAt:endon the navmesh, or the edge the line ran into.hull: Navmesh hull.
Notes
Steps or drops over 20 units stop it. Nav blockers don't. Fails if start is more than 200 units from the navmesh. Cheaper than FindPath.
Source: Nav.cs#L238
Nav.GetRandomPoint()
Returns a random point reachable from origin, between minDistance and maxDistance away, or null if there is none.
Signature
public static Vector3? GetRandomPoint(Vector3 origin, float minDistance, float maxDistance, int hull = 0)
Notes
maxDistance is capped at 6000. Larger values cost more.
Source: Nav.cs#L253
Nav.FindPath()
Finds a path with the game's pathfinder. Returns null if there is none.
Signature
public static NavPath? FindPath(Vector3 start, Vector3 goal, int hull = 0, bool allowPartial = false, bool simplify = true)
public static NavPath? FindPath(Vector3 start, Vector3 goal, CBaseEntity walker, bool allowPartial = false, bool simplify = true)
Parameters
start: Start point.goal: Goal point.hull: Navmesh hull.allowPartial: Accept a path that stops short of the goal. CompareNavPath.Endwith the goal.simplify: Keep only corners. False gives a waypoint per area crossed.
Notes
Both ends must be on the navmesh. Snap them with GetNearestPoint. Takes about 1 ms across half the map, 3 ms for a failed search. Uses the hull's default costs, so it ignores per-NPC rules such as a trooper's lane.
Source: Nav.cs#L272, Nav.cs#L294
Nav.CreateBlocker()
Blocks a box of the navmesh with a script_nav_blocker. NPCs and FindPath route around it. Returns the blocker, or null on failure. Remove the blocker to unblock.
Signature
public static CBaseEntity? CreateBlocker(Vector3 center, Vector3 halfExtents, Vector3? angles = null, int team = 0)
Parameters
center: Box centre.halfExtents: Half the box size on each axis, beforeangles.angles: Pitch, yaw, roll. Null is axis-aligned.team: Team to block, or 0 for everyone.
Notes Takes effect shortly after the call.
Source: Nav.cs#L307
Nav.GetHull()
Returns the hull an NPC or hero paths with, or 0 for other entities.
Signature
public static int GetHull(CBaseEntity entity)
Source: Nav.cs#L323