A* Pathfinding Project  4.0.7
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
RichAI Class Reference

Advanced AI for navmesh based graphs. More...

Detailed Description

Advanced AI for navmesh based graphs.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here

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.
 

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
 

Member Function Documentation

Vector2 CalculateWallForce ( Vector2  position,
float  elevation,
Vector2  directionToTarget 
)
private
void CancelCurrentPathRequest ( )
protected
override Vector3 ClampToNavmesh ( Vector3  position)
protectedvirtual

Constrains the character's position to lie on the navmesh.

Not all movement scripts have support for this.

Reimplemented from AIBase.

void Init ( )
private
override void MovementUpdate ( float  deltaTime)
protectedvirtual

Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not.

Implements AIBase.

void NextPart ( )
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

virtual void OnDisable ( )
protectedvirtual

Called when the component is disabled.

override void OnDrawGizmos ( )
protectedvirtual

Reimplemented from AIBase.

virtual void OnEnable ( )
protectedvirtual

Called when the component is enabled.

void OnPathComplete ( Path  p)
private
virtual void OnTargetReached ( )
protectedvirtual

Called when the end of the path is reached.

IEnumerator SearchPaths ( )
private

Searches for paths periodically.

virtual void Start ( )
protectedvirtual

Starts searching for paths.

If you override this function you should in most cases call base.Start () at the start of it.

See Also
Init
SearchPaths

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.

See Also
Works similarly to Unity's NavmeshAgent.Warp.
void TraverseFunnel ( RichFunnel  fn,
float  deltaTime 
)
private
virtual IEnumerator TraverseSpecial ( RichSpecial  rs)
protectedvirtual

Reimplemented in LegacyRichAI.

virtual void UpdatePath ( )
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).

See Also
Seeker.IsDone

Reimplemented in LocalSpaceRichAI.

virtual Vector3 UpdateTarget ( RichFunnel  fn)
protectedvirtual

Member Data Documentation

float acceleration = 5

Max acceleration of the agent.

In world units per second per second.

Animation anim
bool canSearchPath
protected
bool delayUpdatePath
protected
float distanceToWaypoint = float.PositiveInfinity
protected
float endReachedDistance = 0.01f

Max distance to the endpoint to consider it reached.

In seconds.

See Also
TargetReached
OnTargetReached
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.

readonly Color GizmoColorPath = new Color(8.0f/255, 78.0f/255, 194.0f/255)
staticprotected
bool lastCorner
protected
float lastRepath = float.NegativeInfinity
protected
float maxSpeed = 1

Max speed of the agent.

In world units per second.

readonly List<Vector3> nextCorners = new List<Vector3>()
protected
Vector3 prevPosition = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)
protected

Position of the agent at the end of the previous frame.

Vector3 realVelocity
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.

See Also
SearchPaths
bool repeatedlySearchPaths = false

Search for new paths repeatedly.

See Also
repathRate
SearchPaths
readonly RichPath richPath = new RichPath()
protected

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.

Note
The agent may require more time to slow down if its maximum acceleration is not high enough.

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.

Note
A value of zero will behave differently from a small but non-zero value (such as 0.0001). When it is non-zero the agent will still respect its acceleration when determining if it needs to slow down, but if it is zero it will disable that check.
bool slowWhenNotFacingTarget = true

Slow down when not facing the target direction.

Incurs at a small performance overhead.

bool startHasRun
private
Transform target

Target position to move to.

bool traversingSpecialPath
protected
bool waitingForPathCalc
protected
readonly List<Vector3> wallBuffer = new List<Vector3>()
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

See Also
wallForce
float wallForce = 3

Force to avoid walls with.

The agent will try to steer away from walls slightly.

See Also
wallDist
Vector3 waypoint
private

Property Documentation

bool ApproachingPartEndpoint
get

True if approaching the last waypoint in the current part of the path.

Path parts are separated by off-mesh links.

See Also
ApproachingPathEndpoint
bool ApproachingPathEndpoint
get

True if approaching the last waypoint of all parts in the current path.

Path parts are separated by off-mesh links.

See Also
ApproachingPartEndpoint
float DistanceToNextWaypoint
get

Distance to the next waypoint.

See Also
NextWaypoint
Vector3 NextWaypoint
get

Waypoint that the agent is moving towards.

This is either a corner in the path or the end of the path.

See Also
DistanceToNextWaypoint
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.

Deprecated:
This property has been renamed to NextWaypoint
bool TargetReached
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.

bool TraversingSpecial
get
Vector3 Velocity
get

Current velocity of the agent.

Includes velocity due to gravity.


The documentation for this class was generated from the following file: