A* Pathfinding Project
4.0.0
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 | centerOffset = 1 |
Offset along the Y coordinate for the ground raycast start position. | |
float | endReachedDistance = 0.01f |
Max distance to the endpoint to consider it reached. | |
bool | funnelSimplification = false |
Use funnel simplification. | |
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 of the agent. | |
bool | raycastingForGroundPlacement = true |
Raycast for ground placement (when not having a CharacterController). | |
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. | |
Protected Member Functions | |
override void | Awake () |
void | CancelCurrentPathRequest () |
void | NextPart () |
Declare that the AI has completely traversed the current part. | |
virtual void | OnDisable () |
Called when the component is disabled. | |
virtual 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 void | Update () |
Update is called once per frame. | |
virtual Vector3 | UpdateTarget (RichFunnel fn) |
Protected Member Functions inherited from VersionedMonoBehaviour | |
virtual int | OnUpgradeSerializedData (int version) |
Handle serialization backwards compatibility. | |
Protected Attributes | |
bool | canSearchPath |
CharacterController | controller |
Cached CharacterController component. | |
bool | delayUpdatePath |
float | distanceToWaypoint = float.PositiveInfinity |
bool | lastCorner |
float | lastRepath = float.NegativeInfinity |
IMovementPlane | movementPlane = GraphTransform.identityTransform |
List< Vector3 > | nextCorners = new List<Vector3>() |
Vector3 | prevPosition |
Position of the agent at the end of the previous frame. | |
Vector3 | realVelocity |
Current velocity of the agent. | |
readonly RichPath | rp = new RichPath() |
Holds the current path that this agent is following. | |
RVOController | rvoController |
Cached RVOController component. | |
Seeker | seeker |
Cached Seeker component. | |
Transform | tr |
Cached Transform component. | |
bool | traversingSpecialPath |
bool | waitingForPathCalc |
List< Vector3 > | wallBuffer = new List<Vector3>() |
Static Protected Attributes | |
static readonly Color | GizmoColorPath = new Color(8.0f/255, 78.0f/255, 194.0f/255) |
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. | |
Private Member Functions | |
Vector2 | CalculateDeltaToMoveThisFrame (Vector2 position, float distanceToEndOfPath) |
Vector2 | CalculateWallForce (Vector2 position, float elevation, Vector2 directionToTarget) |
void | Init () |
void | Move (Vector2 position, float elevation, Vector2 deltaPosition, float deltaElevation, RichFunnel fn) |
void | OnPathComplete (Path p) |
Vector3 | RaycastPosition (Vector2 position, float elevation, float lastElevation) |
Find the world position of the ground below the character. | |
void | RotateTowards (Vector2 direction, float degreesPerSecond) |
Rotates along the Y-axis so that the transform's forward direction points in the direction direction. | |
IEnumerator | SearchPaths () |
Searches for paths periodically. | |
void | TraverseFunnel (RichFunnel fn) |
Static Private Member Functions | |
static void | PlotTrajectory (Vector2 origin, Vector2 v, Vector2 a, Vector2 q, float tmax) |
Private Attributes | |
bool | startHasRun |
Vector2 | velocity |
Current desired velocity of the agent. | |
float | verticalVelocity |
Velocity due to gravity. | |
Vector3 | waypoint |
Static Private Attributes | |
static float | deltaTime |
Delta time to use for the current frame. | |
|
protectedvirtual |
Reimplemented from VersionedMonoBehaviour.
Reimplemented in LegacyRichAI.
|
private |
|
private |
|
protected |
|
private |
|
private |
|
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 |
|
protectedvirtual |
Called when the component is enabled.
|
private |
|
protectedvirtual |
Called when the end of the path is reached.
|
staticprivate |
|
private |
Find the world position of the ground below the character.
|
private |
Rotates along the Y-axis so that the transform's forward direction points in the direction direction.
|
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.
|
protectedvirtual |
Update is called once per frame.
Reimplemented in LocalSpaceRichAI, and 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 |
float centerOffset = 1 |
Offset along the Y coordinate for the ground raycast start position.
Normally the pivot of the character is at the character's feet, but you usually want to fire the raycast from the character's center, so this value should be half of the character's height.
A green gizmo line will be drawn upwards from the pivot point of the character to indicate where the raycast will start.
|
protected |
Cached CharacterController component.
|
protected |
|
staticprivate |
Delta time to use for the current frame.
|
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 |
|
staticprotected |
Vector3 gravity = new Vector3(float.NaN, float.NaN, float.NaN) |
Gravity to use.
If set to (NaN,NaN,NaN) then Physics.Gravity (configured in the Unity project settings) will be used.
LayerMask groundMask = -1 |
Layer mask to use for ground placement.
Make sure this does not include the layer of any colliders attached to this gameobject.
|
protected |
|
protected |
float maxSpeed = 1 |
Max speed of the agent.
In world units per second.
|
protected |
|
protected |
|
protected |
Position of the agent at the end of the previous frame.
bool raycastingForGroundPlacement = true |
Raycast for ground placement (when not having a CharacterController).
A raycast from position + up*centerOffset downwards will be done and the agent will be placed at this point.
This field will only show up in the inspector if no CharacterController is attached to the same GameObject.
|
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.
float rotationSpeed = 360 |
Max rotation speed of the agent.
In degrees per second.
Holds the current path that this agent is following.
|
protected |
Cached RVOController component.
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.
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 |
Cached Transform component.
|
protected |
|
private |
Current desired velocity of the agent.
|
private |
Velocity due to gravity.
|
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.