|
delegate void | FailedToFindPathDelegate (NavAgent agent) |
|
bool | WarpToNearestSegment () |
| Repositions the agent at the nearest segment the agent could be standing at. Segments the agent could not be at do to its tag or slope will be ignored. More...
|
|
bool | PathTo (params Vector2[] goals) |
| Starts the process of pathfinding to the closest of the given goals. NOTE: Do not call this method every frame. Calculating a path takes longer than a frame, so the agent will never start moving. More...
|
|
bool | PathTo (Vector2 goal) |
| Starts the process of pathfinding to the given goal. NOTE: Do not call this method every frame. Calculating a path takes longer than a frame, so the agent will never start moving. More...
|
|
bool | UpdatePath (params Vector2[] goals) |
| Starts the process of pathfinding to the closest of the given goals. Will continue moving until the calculations for the new path are completed. NOTE: Do not call this method every frame. Calculating a path takes longer than a frame, so the agent will never start moving. More...
|
|
bool | UpdatePath (Vector2 goal) |
| Starts the process of pathfinding to the given goal. Will continue moving until the calculations for the new path are completed. NOTE: Do not call this method every frame. Calculating a path takes longer than a frame, so the agent will never start moving. More...
|
|
bool | HasReachedCurrentSubGoal (float maxDist=0.05f) |
| Simple distance check between agent and CurrentSubGoal. More...
|
|
bool | SetRandomDestination () |
| Start pathfinding to a random position on the NavGraph. It cannot grantee that this position is reachable. Does the agent might not move after this is called. More...
|
|
void | CompleteLinkTraversal () |
| If you implement link traversal yourself, call this to complete a link traversal. More...
|
|
void | CompleteSegmentTraversal () |
| If you implement segment traversal yourself, call this to complete a segment traversal. More...
|
|
bool | CanTraverseLink (INavLinkInstance link) |
| Determines, if in this agent is allowed to traverse the given link. More...
|
|
float | GetLinkTraversalMultiplier (int linkType) |
| Get the traversal cost multiplier for a given link type. More...
|
|
float | GetNavTagTraversalMultiplier (int navTag) |
| Get the traversal cost multiplier for a given nav tag. More...
|
|
bool | IsOnSegmentWithTag (int navTag) |
| Whether the agents current position contains the given NavTag. NOTE: Does not work, if the agent is not currently moving on a path. More...
|
|
void | Stop () |
| Stops the current path following at the first opportunity. Link traversal will be completed before the agent stops. More...
|
|
void | ForceStop () |
| Stops the current path following instantly. Agent might stop wihle traversing a link (e.g. while jumping in mid air) More...
|
|
bool? | IsOnSameSegmentAs (Vector2 other) |
| Tries to map the "other" and checks if the agent is mapped to the same segment. If "other" can't be mapped this will return null. Agents on a link will always return false. If this agent currently can't be mapped this will return null. More...
|
|
IEnumerable< Vector2 > | PathPoints () |
| Enumerates the points on the currently followed path. Corner links will result in the same point being enumerated twice in a row. First point will be the agents current position. More...
|
|
|
State | CurrentStatus => status |
|
bool | IsIdle => status == State.Idle && currentPathRequest.Status == PathRequest.RequestState.Draft |
|
bool | IsFollowingAPath => status == State.FollowPath |
|
float | Height => height |
|
float | MaxSlopeAngle => maxSlopeAngle |
|
bool | IsOnLink => IsFollowingAPath && movementState == MovementState.OnLink |
|
bool | IsMovingOnSegment => IsFollowingAPath && movementState == MovementState.OnSegment |
|
bool | IsWaitingForLink => IsFollowingAPath && movementState == MovementState.WaitForLinkOnSegment |
|
bool | IsOnSegment => IsFollowingAPath && movementState != MovementState.OnLink |
| If true, either IsMovingOnSegment is true, or the agent is waiting to traverse an untraversable link. More...
|
|
bool | HasValidPosition => !currentMappedPosition.IsInvalid() |
| Check, if the current mapped position of the agent is valid. The mapped position can only be valid, if the agent is close to the ground. (Close, not necessarily directly on the ground) More...
|
|
bool | IsStopping => stopRequested |
| True, if Stop() was called and agent hasn't yet stopped More...
|
|
bool | IsOnGoalSegment => IsOnSegment && !Path.HasNext |
| True, if the agent is on the last segment of its path. More...
|
|
INavLinkInstance | CurrentLink => currentPath?.CurrentSegment.link ?? null |
| Link of the path segment the agent is on, or null. More...
|
|
string | CurrentLinkType => currentPath?.CurrentSegment.link?.LinkTypeName ?? "" |
| Link type of the path segment the agent is on, or "" More...
|
|
Vector2 | CurrentLinkStart => currentPath?.CurrentSegment.LinkStart ?? Vector2.zero |
| Link start of the path segment the agent is on, or Vector2.zero More...
|
|
Vector2 | CurrentSegmentNormal => IsFollowingAPath ? currentPath.CurrentSegment.SegmentNormal : (currentMappedPosition.cluster?.Normal ?? Vector2.up) |
| Segment normal of the path segment the agent is on, or Vector2.up More...
|
|
Vector2 | NextSegmentNormal => currentPath?.NextSegment?.SegmentNormal ?? Vector2.zero |
| Segment normal of the next segment on the path, or Vector2.zero More...
|
|
Vector2 | PathGoal => currentPath?.Goal ?? Vector2.zero |
| Overall goal of the path the agent is on More...
|
|
int | CurrentNavTagVector => IsFollowingAPath ? currentPath.CurrentSegment.GetTagVector(Position) : (currentMappedPosition.cluster?.GetNavTagVector(currentMappedPosition.t) ?? 0) |
| Combination of all NavTags at the position of the agent. More...
|
|
float | movementSpeed = 5 |
| Obsolete More...
|
|
float | cornerSpeed = 100 |
| Obsolete More...
|
|
float | jumpSpeed = 5 |
| Obsolete More...
|
|
float | fallSpeed = 5 |
| Obsolete More...
|
|
float | climbSpeed = 5 |
| Obsolete More...
|
|
Represents a pathfinding entity.
This components handles the interaction with the asynchronous pathfinding system. It assumes the agent is a point located at transform.position
. Automatic movement will directly modify the transform this script is attached to. See NavAgent's build-in movement for more detail on movement.
States
At heart the NavAgent is a state machine with the following states:
-
Idle
In this state the agent does nothing and is ready to path to a new location.
-
Planning
The agent has made a path request and is now waiting for its result. A call to PathTo for example would make the agent switch to this state. If the path calculation succeeded, the agent switches into the FollowPath
state. If it didn't succeed however, the agent will switch back into the Idle
state.
-
FollowPath
The agent will follow the a previously calculated path. Depending on whether autoSegmentMovement or autoLinkMovement is set, the path will be followed automatically. The agent has build-in ways to traverse the build-in link types. They don't make use of the physics system. The path will be recalculated at a set interval determined by autoRepathIntervall. This is to ensure the path is up to date with changes in the world. No reactions to changes in the world between recalculations is possible.
Following a path is further subdivided into three states:
-
Segment movement
The agent moves on a line segment. If you move the agent manually, call CompleteSegmentTraversal to switch to the next state.
-
Wait for link
This state is only entered if after the agent finshes moving on a segment, the link it wants to take is currently not traversable. The agent will wait for the link to become traversable again.
-
Traverse link
The agent will move on the link. If you move the agent manually, call CompleteLinkTraversal to begin traversing the next segment.
-
LostPath
The agent was previously in the FollowPath
state, but LostPath was called. In this state, the agent will periodically attempt to find a path to its last goal. This is useful, for if the agent unexpectedly was moved of its previously followed path, it can still attempt to reach its goal. This state is only entered, when in state FollowPath
and LostPath is called.
Pathfinding properties
A NavAgent has a few properties relevant to the pathfinder.
-
height
Only segments and links with enough free space are considered.
-
maxSlopeAngle
Only segments that don't exceed this angle are considered traversable. 0° = ground, 90° = straight walls and 180° = ceiling.
-
linkTraversalCostMultipliers
For each link one multiplier from this array is applied to its traversal costs. With multiplier values <= 0 you can completely exclude certain link types from traversal.
-
navTagTraversalCostMultipliers
Links and parts of segments can be tagged with a NavTag. NavTag with index 0 is considered the default and applied to all segments that don't have another NavTag. As with linkTraversalCostMultipliers multiplier values <= 0 completely exclude NavTags from traversal.