A* Pathfinding Project
4.0.9
The A* Pathfinding Project for Unity 3D
|
Advanced AI for navmesh based graphs. More...
Advanced AI for navmesh based graphs.
Public Member Functions | |
void | Teleport (Vector3 newPosition) |
Instantly moves the agent to the target position. | |
virtual void | UpdatePath () |
Force recalculation of the current path. | |
Public Attributes | |
float | acceleration = 5 |
Max acceleration of the agent. | |
Animation | anim |
float | endReachedDistance = 0.01f |
Max distance to the endpoint to consider it reached. | |
bool | funnelSimplification = false |
Use funnel simplification. | |
float | maxSpeed = 1 |
Max speed of the agent. | |
float | repathRate = 0.5f |
Delay (seconds) between path searches. | |
bool | repeatedlySearchPaths = false |
Search for new paths repeatedly. | |
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. | |
Transform | target |
Target position to move to. | |
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 | |
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. | |
bool | rotationIn2D = false |
If true, the forward axis of the character will be along the Y axis instead of the Z axis. | |
Protected Member Functions | |
void | CancelCurrentPathRequest () |
override Vector3 | ClampToNavmesh (Vector3 position) |
Constrains the character's position to lie on the navmesh. | |
override void | MovementUpdate (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. | |
virtual void | OnDisable () |
Called when the component is disabled. | |
override void | OnDrawGizmos () |
virtual void | OnEnable () |
Called when the component is enabled. | |
virtual void | OnTargetReached () |
Called when the end of the path is reached. | |
virtual void | Start () |
Starts searching for paths. | |
virtual IEnumerator | TraverseSpecial (RichSpecial rs) |
virtual Vector3 | UpdateTarget (RichFunnel fn) |
Protected Member Functions inherited from AIBase | |
void | ApplyGravity (float deltaTime) |
override void | Awake () |
Initializes reference variables. | |
Vector2 | CalculateDeltaToMoveThisFrame (Vector2 position, float distanceToEndOfPath, float deltaTime) |
virtual void | FixedUpdate () |
Called every physics update. | |
void | Move (Vector3 position3D, Vector3 deltaPosition) |
Vector3 | RaycastPosition (Vector3 position, float lastElevation) |
Find the world position of the ground below the character. | |
virtual void | RotateTowards (Vector2 direction, float maxDegrees) |
Rotates in the specified direction. | |
virtual void | Update () |
Called every frame. | |
Protected Member Functions inherited from VersionedMonoBehaviour | |
virtual int | OnUpgradeSerializedData (int version) |
Handle serialization backwards compatibility. | |
Protected Attributes | |
bool | canSearchPath |
bool | delayUpdatePath |
float | distanceToWaypoint = float.PositiveInfinity |
bool | lastCorner |
float | lastRepath = float.NegativeInfinity |
readonly List< Vector3 > | nextCorners = new List<Vector3>() |
Vector3 | prevPosition = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity) |
Position of the agent at the end of the previous frame. | |
Vector3 | realVelocity |
Current velocity of the agent. | |
readonly RichPath | richPath = new RichPath() |
Holds the current path that this agent is following. | |
bool | traversingSpecialPath |
bool | waitingForPathCalc |
readonly List< Vector3 > | wallBuffer = new List<Vector3>() |
Protected Attributes inherited from AIBase | |
CharacterController | controller |
Cached CharacterController component. | |
IMovementPlane | movementPlane = GraphTransform.identityTransform |
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. | |
float | verticalVelocity |
Velocity due to gravity. | |
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 | |
bool | ApproachingPartEndpoint [get] |
True if approaching the last waypoint in the current part of the path. | |
bool | ApproachingPathEndpoint [get] |
True if approaching the last waypoint of all parts in the current path. | |
float | DistanceToNextWaypoint [get] |
Distance to the next waypoint. | |
Vector3 | NextWaypoint [get] |
Waypoint that the agent is moving towards. | |
bool | PathPending [get] |
True if a path to the target is currently being calculated. | |
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 | TraversingSpecial [get] |
Vector3 | Velocity [get] |
Current velocity of the agent. | |
Properties inherited from AIBase | |
bool | usingGravity [get, set] |
Indicates if gravity is used during this frame. | |
Private Member Functions | |
Vector2 | CalculateWallForce (Vector2 position, float elevation, Vector2 directionToTarget) |
void | Init () |
void | OnPathComplete (Path p) |
IEnumerator | SearchPaths () |
Searches for paths periodically. | |
void | TraverseFunnel (RichFunnel fn, float deltaTime) |
Private Attributes | |
bool | startHasRun |
Vector3 | waypoint |
|
private |
|
protected |
|
protectedvirtual |
Constrains the character's position to lie on the navmesh.
Not all movement scripts have support for this.
Reimplemented from AIBase.
|
private |
|
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.
|
protectedvirtual |
Reimplemented from AIBase.
|
protectedvirtual |
Called when the component is enabled.
|
private |
|
protectedvirtual |
Called when the end of the path is reached.
|
private |
Searches for paths periodically.
|
protectedvirtual |
Starts searching for paths.
If you override this function you should in most cases call base.Start () at the start of it.
Reimplemented in LocalSpaceRichAI.
void Teleport | ( | Vector3 | newPosition | ) |
Instantly moves the agent to the target position.
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.
The current path will be cleared.
|
private |
|
protectedvirtual |
Reimplemented in LegacyRichAI.
|
virtual |
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).
Reimplemented in LocalSpaceRichAI.
|
protectedvirtual |
float acceleration = 5 |
Max acceleration of the agent.
In world units per second per second.
Animation anim |
|
protected |
|
protected |
|
protected |
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.
|
staticprotected |
|
protected |
|
protected |
float maxSpeed = 1 |
Max speed of the agent.
In world units per second.
|
protected |
|
protected |
Position of the agent at the end of the previous frame.
|
protected |
Current velocity of the agent.
float repathRate = 0.5f |
Delay (seconds) between path searches.
The agent will plan a new path to the target every N seconds.
bool repeatedlySearchPaths = false |
Search for new paths repeatedly.
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.
|
private |
Transform target |
Target position to move to.
|
protected |
|
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 |
|
private |
|
get |
True if approaching the last waypoint in the current part of the path.
Path parts are separated by off-mesh links.
|
get |
True if approaching the last waypoint of all parts in the current path.
Path parts are separated by off-mesh links.
|
get |
Distance to the next waypoint.
|
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 |
Current waypoint that the agent is moving towards.
|
get |
True if the agent is within endReachedDistance units from the end of the current path.
Note that if the target was just changed, a new path may not be calculated immediately and thus this value will correspond to if the previous target had been reached.
To be sure if a character has reached a particular target you can make sure to call UpdatePath when you change the target position and then check for !PathPending && TargetReached. The PathPending property indicates if the new path has been calculated yet.
|
get |
|
get |
Current velocity of the agent.
Includes velocity due to gravity.