A* Pathfinding Project
4.1.0
The A* Pathfinding Project for Unity 3D
|
Advanced AI for navmesh based graphs. More...
Advanced AI for navmesh based graphs.
Public Member Functions | |
override void | OnPathComplete (Path p) |
Called when a requested path has been calculated. | |
override void | SearchPath () |
Recalculate the current path. | |
override void | Teleport (Vector3 newPosition, bool clearPath=true) |
Instantly move the agent to a new position. | |
void | UpdatePath () |
Force recalculation of the current path. | |
Public Member Functions inherited from AIBase | |
virtual Vector3 | GetFeetPosition () |
Position of the base of the character. | |
void | MovementUpdate (float deltaTime, bool useGravity) |
Calculate all movement for a single movement step and move the character. | |
Public Member Functions inherited from IAstarAI | |
void | MovementUpdate (float deltaTime, bool useGravity) |
Calculate all movement for a single movement step and move the agent. | |
void | SearchPath () |
Recalculate the current path. | |
void | Teleport (Vector3 newPosition, bool clearPath=true) |
Instantly move the agent to a new position. | |
Public Member Functions inherited from IAstarAIMovement | |
Vector3 | ClampToNavmesh (Vector3 position, out bool positionChanged) |
Clamps the agent's position to the navmesh. | |
void | Move (Vector3 position, Vector3 deltaPosition) |
Move the agent. | |
void | RotateTowards (Vector3 direction, float maxDegrees) |
Rotates towards the specified direction. | |
void | UpdateVelocity (Vector3 position) |
To be called after all movement is done with the position of the agent. | |
Public Attributes | |
float | acceleration = 5 |
Max acceleration of the agent. | |
float | endReachedDistance = 0.01f |
Max distance to the endpoint to consider it reached. | |
bool | funnelSimplification = false |
Use funnel simplification. | |
System.Func< RichSpecial, IEnumerator > | onTraverseOffMeshLink |
Called when the agent starts to traverse an off-mesh link. | |
float | rotationSpeed = 360 |
Max rotation speed of the agent. | |
float | slowdownTime = 0.5f |
How long before reaching the end of the path to start to slow down. | |
bool | slowWhenNotFacingTarget = true |
Slow down when not facing the target direction. | |
float | wallDist = 1 |
Walls within this range will be used for avoidance. | |
float | wallForce = 3 |
Force to avoid walls with. | |
Public Attributes inherited from AIBase | |
bool | canMove = true |
Enables or disables movement completely. | |
bool | canSearch = true |
Enables or disables recalculating the path at regular intervals. | |
float | centerOffset = 1 |
Offset along the Y coordinate for the ground raycast start position. | |
Vector3 | gravity = new Vector3(float.NaN, float.NaN, float.NaN) |
Gravity to use. | |
LayerMask | groundMask = -1 |
Layer mask to use for ground placement. | |
float | maxSpeed = 1 |
Max speed in world units per second. | |
IMovementPlane | movementPlane = GraphTransform.identityTransform |
Plane which this agent is moving in. | |
float | repathRate = 0.5f |
Determines how often the agent will search for new paths (in seconds). | |
bool | rotationIn2D = false |
If true, the forward axis of the character will be along the Y axis instead of the Z axis. | |
bool | updatePosition = true |
Determines if the character should move or if just the desired velocities should be calculated. | |
bool | updateRotation = true |
Determines if the character should rotate automatically. | |
Protected Member Functions | |
override Vector3 | ClampToNavmesh (Vector3 position, out bool positionChanged) |
Constrains the character's position to lie on the navmesh. | |
override void | MovementUpdateInternal (float deltaTime) |
Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not. | |
void | NextPart () |
Declare that the AI has completely traversed the current part. | |
override void | OnDisable () |
Called when the component is disabled. | |
override void | OnDrawGizmos () |
virtual void | OnTargetReached () |
Called when the end of the path is reached. | |
override int | OnUpgradeSerializedData (int version, bool unityThread) |
Handle serialization backwards compatibility. | |
IEnumerator | TraverseOffMeshLinkFallback (RichSpecial link) |
Fallback for traversing off-mesh links in case onTraverseOffMeshLink is not set. | |
virtual IEnumerator | TraverseSpecial (RichSpecial link) |
Traverses an off-mesh link. | |
virtual Vector3 | UpdateTarget (RichFunnel fn) |
Protected Member Functions inherited from AIBase | |
AIBase () | |
void | ApplyGravity (float deltaTime) |
Accelerates the agent downwards. | |
override void | Awake () |
Initializes reference variables. | |
Vector2 | CalculateDeltaToMoveThisFrame (Vector2 position, float distanceToEndOfPath, float deltaTime) |
Calculates how far to move during a single frame. | |
virtual void | CalculatePathRequestEndpoints (out Vector3 start, out Vector3 end) |
Outputs the start point and end point of the next automatic path request. | |
void | CancelCurrentPathRequest () |
virtual void | FixedUpdate () |
Called every physics update. | |
virtual void | OnEnable () |
Called when the component is enabled. | |
Vector3 | RaycastPosition (Vector3 position, float lastElevation) |
Checks if the character is grounded and prevents ground penetration. | |
IEnumerator | RepeatTrySearchPath () |
Tries to search for a path every repathRate seconds. | |
virtual void | RotateTowards (Vector2 direction, float maxDegrees) |
Rotates towards the specified direction. | |
virtual void | Start () |
Starts searching for paths. | |
virtual void | Update () |
Called every frame. | |
void | UpdateVelocity (Vector3 position) |
Protected Attributes | |
bool | delayUpdatePath |
float | distanceToSteeringTarget = float.PositiveInfinity |
Distance to steeringTarget in the movement plane. | |
bool | lastCorner |
readonly List< Vector3 > | nextCorners = new List<Vector3>() |
readonly RichPath | richPath = new RichPath() |
Holds the current path that this agent is following. | |
bool | traversingSpecialPath |
readonly List< Vector3 > | wallBuffer = new List<Vector3>() |
Protected Attributes inherited from AIBase | |
CharacterController | controller |
Cached CharacterController component. | |
Vector3 | lastDeltaPosition |
Amount which the character wants or tried to move with during the last frame. | |
float | lastDeltaTime |
Delta time used for movement during the last frame. | |
float | lastRepath = float.NegativeInfinity |
Time when the last path request was started. | |
Vector3 | prevPosition1 |
Position of the character at the end of the last frame. | |
Vector3 | prevPosition2 |
Position of the character at the end of the frame before the last frame. | |
Rigidbody | rigid |
Cached Rigidbody component. | |
Rigidbody2D | rigid2D |
Cached Rigidbody component. | |
RVOController | rvoController |
Cached RVOController component. | |
Seeker | seeker |
Cached Seeker component. | |
Transform | tr |
Cached Transform component. | |
Vector2 | velocity2D |
Current desired velocity of the agent (does not include local avoidance and physics). | |
float | verticalVelocity |
Velocity due to gravity. | |
bool | waitingForPathCalculation = false |
Only when the previous path has been calculated should the script consider searching for a new path. | |
Static Protected Attributes | |
static readonly Color | GizmoColorPath = new Color(8.0f/255, 78.0f/255, 194.0f/255) |
Static Protected Attributes inherited from AIBase | |
static readonly Color | GizmoColorRaycast = new Color(118.0f/255, 206.0f/255, 112.0f/255) |
Properties | |
Animation | anim [get, set] |
Anim for off-mesh links. | |
bool | ApproachingPartEndpoint [get] |
bool | approachingPartEndpoint [get] |
True if approaching the last waypoint in the current part of the path. | |
bool | ApproachingPathEndpoint [get] |
bool | approachingPathEndpoint [get] |
True if approaching the last waypoint of all parts in the current path. | |
bool IAstarAI. | canMove [get, set] |
Enables or disables movement completely. | |
bool IAstarAI. | canSearch [get, set] |
Enables or disables recalculating the path at regular intervals. | |
float | DistanceToNextWaypoint [get] |
bool | hasPath [get] |
True if this agent currently has a path that it follows. | |
float IAstarAI. | maxSpeed [get, set] |
Max speed in world units per second. | |
Vector3 | NextWaypoint [get] |
Waypoint that the agent is moving towards. | |
bool | PathPending [get] |
True if a path to the target is currently being calculated. | |
bool | pathPending [get] |
True if a path is currently being calculated. | |
Vector3 IAstarAI. | position [get] |
Position of the agent. | |
float | remainingDistance [get] |
Remaining distance along the current path to the destination. | |
bool | repeatedlySearchPaths [get, set] |
Search for new paths repeatedly. | |
override bool | shouldRecalculatePath [get] |
Vector3 | steeringTarget [get, set] |
Point on the path which the agent is currently moving towards. | |
Vector3 | TargetPoint [get] |
Current waypoint that the agent is moving towards. | |
bool | TargetReached [get] |
True if the agent is within endReachedDistance units from the end of the current path. | |
bool | targetReached [get] |
True if the agent has reached the end of the current path. | |
bool | TraversingSpecial [get] |
Vector3 | Velocity [get] |
Current velocity of the agent. | |
Properties inherited from AIBase | |
Vector3 | desiredVelocity [get] |
Velocity that this agent wants to move with. | |
Vector3 | destination [get, set] |
Position in the world that this agent should move to. | |
bool | isStopped [get, set] |
Gets or sets if the agent should stop moving. | |
System.Action | onSearchPath [get, set] |
virtual bool | shouldRecalculatePath [get] |
True if the path should be automatically recalculated as soon as possible. | |
Transform | target [get, set] |
Target to move towards. | |
bool | usingGravity [get, set] |
Indicates if gravity is used during this frame. | |
Vector3 | velocity [get] |
Actual velocity that the agent is moving with. | |
Properties inherited from IAstarAI | |
bool | canMove [get, set] |
Enables or disables movement completely. | |
bool | canSearch [get, set] |
Enables or disables recalculating the path at regular intervals. | |
Vector3 | desiredVelocity [get] |
Velocity that this agent wants to move with. | |
Vector3 | destination [get, set] |
Position in the world that this agent should move to. | |
bool | hasPath [get] |
True if this agent currently has a path that it follows. | |
bool | isStopped [get, set] |
Gets or sets if the agent should stop moving. | |
float | maxSpeed [get, set] |
Max speed in world units per second. | |
System.Action | onSearchPath [get, set] |
Called when the agent recalculates its path. | |
bool | pathPending [get] |
True if a path is currently being calculated. | |
Vector3 | position [get] |
Position of the agent. | |
float | remainingDistance [get] |
Remaining distance along the current path to the destination. | |
Vector3 | steeringTarget [get] |
Point on the path which the agent is currently moving towards. | |
bool | targetReached [get] |
True if the agent has reached the end of the current path. | |
Vector3 | velocity [get] |
Actual velocity that the agent is moving with. | |
Private Member Functions | |
Vector2 | CalculateWallForce (Vector2 position, float elevation, Vector2 directionToTarget) |
Vector3 IAstarAIMovement. | ClampToNavmesh (Vector3 position, out bool positionChanged) |
Clamps the agent's position to the navmesh. | |
void | FinalMovement (Vector3 position3D, float deltaTime, float distanceToEndOfPath, float slowdownFactor) |
void IAstarAIMovement. | Move (Vector3 position, Vector3 deltaPosition) |
Move the agent. | |
void IAstarAIMovement. | RotateTowards (Vector3 direction, float maxDegrees) |
Rotates towards the specified direction. | |
void | TraverseFunnel (RichFunnel fn, float deltaTime) |
void IAstarAIMovement. | UpdateVelocity (Vector3 position) |
To be called after all movement is done with the position of the agent. | |
Private Attributes | |
Animation | animCompatibility |
|
private |
|
protectedvirtual |
Constrains the character's position to lie on the navmesh.
Not all movement scripts have support for this.
position | Current position of the character. |
positionChanged | True if the character's position was modified by this method. |
Reimplemented from AIBase.
|
privatevirtual |
Clamps the agent's position to the navmesh.
position | Position of the agent. |
positionChanged | True if the agent's position had to be modified. |
Reimplemented from AIBase.
|
private |
|
privatevirtual |
Move the agent.
position | Position of the agent. |
deltaPosition | Direction and distance to move the agent in world space. |
Reimplemented from AIBase.
|
protectedvirtual |
Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not.
Implements AIBase.
|
protected |
Declare that the AI has completely traversed the current part.
This will skip to the next part, or call OnTargetReached if this was the last part
|
protectedvirtual |
Called when the component is disabled.
Reimplemented from AIBase.
|
protectedvirtual |
Reimplemented from AIBase.
|
virtual |
Called when a requested path has been calculated.
Implements AIBase.
|
protectedvirtual |
Called when the end of the path is reached.
|
protectedvirtual |
Handle serialization backwards compatibility.
Reimplemented from AIBase.
|
private |
Rotates towards the specified direction.
direction | Direction rotate towards. |
maxDegrees | Maximum number of degrees to rotate this frame. |
|
virtual |
Recalculate the current path.
You can for example use this if you want very quick reaction times when you have changed the destination so that the agent does not have to wait until the next automatic path recalculation (see canSearch).If there is an ongoing path calculation, it will be canceled, so make sure you leave time for the paths to get calculated before calling this function again. A canceled path will show up in the log with the message "Canceled by script" (see Seeker.CancelCurrentPathRequest()).If no destination has been set yet then nothing will be done.
Reimplemented from AIBase.
|
virtual |
Instantly move the agent to a new position.
This will trigger a path recalculation (if clearPath is true, which is the default) so if you want to teleport the agent and change its destination it is recommended that you set the destination before calling this method.The current path will be cleared by default.
When setting transform.position directly the agent will be clamped to the part of the navmesh it can reach, so it may not end up where you wanted it to. This ensures that the agent can move to any part of the navmesh.
Reimplemented from AIBase.
|
private |
|
protected |
Fallback for traversing off-mesh links in case onTraverseOffMeshLink is not set.
This will do a simple linear interpolation along the link.
|
protectedvirtual |
Traverses an off-mesh link.
void UpdatePath | ( | ) |
Force recalculation of the current path.
If there is an ongoing path calculation, it will be canceled (so make sure you leave time for the paths to get calculated before calling this function again).
|
protectedvirtual |
|
private |
To be called after all movement is done with the position of the agent.
position | Current position of the agent (as a parameter mostly for performance reasons as reading from transform.position can be slow). |
You have to call this if you are handling movement manually to make sure e.g the velocity field is up to date.This is automatically called by the Move method, so if you are using that method this should not be called.
float acceleration = 5 |
Max acceleration of the agent.
In world units per second per second.
|
private |
|
protected |
|
protected |
Distance to steeringTarget in the movement plane.
float endReachedDistance = 0.01f |
Max distance to the endpoint to consider it reached.
In seconds.
bool funnelSimplification = false |
Use funnel simplification.
On tiled navmesh maps, but sometimes on normal ones as well, it can be good to simplify the funnel as a post-processing step to make the paths straighter.
This has a moderate performance impact during frames when a path calculation is completed.
The RichAI script uses its own internal funnel algorithm, so you never need to attach the FunnelModifier component.
|
staticprotected |
|
protected |
|
protected |
System.Func<RichSpecial, IEnumerator> onTraverseOffMeshLink |
Called when the agent starts to traverse an off-mesh link.
Register to this callback to handle off-mesh links in a custom way.
If this event is set to null then the agent will fall back to traversing off-mesh links using a very simple linear interpolation.
Holds the current path that this agent is following.
float rotationSpeed = 360 |
Max rotation speed of the agent.
In degrees per second.
float slowdownTime = 0.5f |
How long before reaching the end of the path to start to slow down.
A lower value will make the agent stop more abruptly.
If set to zero the agent will not even attempt to slow down. This can be useful if the target point is not a point you want the agent to stop at but it might for example be the player and you want the AI to slam into the player.
bool slowWhenNotFacingTarget = true |
Slow down when not facing the target direction.
Incurs at a small performance overhead.
|
protected |
|
protected |
float wallDist = 1 |
Walls within this range will be used for avoidance.
Setting this to zero disables wall avoidance and may improve performance slightly
float wallForce = 3 |
|
getset |
Anim for off-mesh links.
|
get |
|
get |
True if approaching the last waypoint in the current part of the path.
Path parts are separated by off-mesh links.
|
get |
|
get |
True if approaching the last waypoint of all parts in the current path.
Path parts are separated by off-mesh links.
|
getsetprivate |
|
getsetprivate |
Enables or disables recalculating the path at regular intervals.
Setting this to false does not stop any active path requests from being calculated or stop it from continuing to follow the current path.Note that this only disables automatic path recalculations. If you call the SearchPath() method a path will still be calculated.
|
get |
|
get |
True if this agent currently has a path that it follows.
|
getsetprivate |
Max speed in world units per second.
|
get |
Waypoint that the agent is moving towards.
This is either a corner in the path or the end of the path.
|
get |
True if a path to the target is currently being calculated.
|
get |
True if a path is currently being calculated.
|
getprivate |
|
get |
Remaining distance along the current path to the destination.
For the RichAI movement script this may not always be precisely known, especially when far away from the destination. In those cases an approximate distance will be returned.If the agent does not currently have a path, then positive infinity will be returned.
|
getset |
Search for new paths repeatedly.
|
getprotected |
|
getset |
Point on the path which the agent is currently moving towards.
This is usually a point a small distance ahead of the agent or the end of the path.If the agent does not have a path at the moment, then the agent's current position will be returned.
|
get |
Current waypoint that the agent is moving towards.
|
get |
True if the agent is within endReachedDistance units from the end of the current path.
|
get |
True if the agent has reached the end of the current path.
|
get |
|
get |
Current velocity of the agent.
Includes velocity due to gravity.