Vixen
02b45cc4
csharp
public sealed class PathCorridor

The polygons an agent is walking through, kept up to date as it moves.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

An agent does not follow a line, it follows a corridor. The expensive search happens once, when the destination changes; after that every frame only trims the polygons the agent has left off the front and pulls a fresh set of corners out of what remains. That is what makes a hundred agents affordable — the per-frame cost is a string-pull over a handful of polygons, not a search.

It is also what makes local avoidance safe. Avoidance pushes an agent sideways, off the line it would have walked; because the corridor is a region rather than a line, the agent is still inside its path afterwards and no replan is needed.

Fields and properties (6)

  • public Vector3 Position

    Where the agent is.

  • public Vector3 Target

    Where it is going.

  • public int Count

    How many polygons the corridor holds.

  • public NavPolyRef FirstPoly

    The polygon the agent is on.

  • public NavPolyRef LastPoly

    The polygon the target is on.

  • public ReadOnlySpan<NavPolyRef> Path

    The corridor, for a caller that wants to look at it.

Methods (8)

  • public PathCorridor(int capacity = 256)

    Creates a corridor.

  • public void Reset(NavPolyRef poly, Vector3 position)

    Throws the corridor away and starts again from one polygon.

  • public void SetPath(Vector3 target, ReadOnlySpan<NavPolyRef> corridor)

    Gives the corridor a path to follow.

  • public int FindCorners(NavMeshQuery query, Span<NavPathPoint> corners)

    The corners the agent has to turn at, starting from where it is.

  • public bool MovePosition(Vector3 wanted, NavMeshQuery query, NavQueryFilter filter)

    Moves the agent, keeping it on the mesh and trimming the polygons it has walked past.

  • public bool TryUseOffMeshConnection(NavMesh mesh, float reach, out NavPolyRef connection, out Vector3 entry, out Vector3 exit)

    Steps onto the off-mesh connection the corridor is about to use, if the agent has arrived at its near end.

  • public void Optimize(NavMeshQuery query, NavQueryFilter filter, float distance = 6)

    Cuts the corridor short wherever the agent can already see past it.

  • public void EnsureCapacity(int capacity)

    Makes room for a longer path.

Used by (2)

  • AgentVixen.Navigation
  • CrowdVixen.Navigation