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
LocalSpaceRichAI Class Reference

RichAI for local space (pathfinding on moving graphs). More...

Detailed Description

RichAI for local space (pathfinding on moving graphs).

What this script does is that it fakes graph movement. It can be seen in the example scene called 'Moving' where a character is pathfinding on top of a moving ship. The graph does not actually move in that example instead there is some 'cheating' going on.

When requesting a path, we first transform the start and end positions of the path request into local space for the object we are moving on (e.g the ship in the example scene), then when we get the path back, they will still be in these local coordinates. When following the path, we will every frame transform the coordinates of the waypoints in the path to global coordinates so that we can follow them.

At the start of the game (when the graph is scanned) the object we are moving on should be at a valid position on the graph and you should attach the Pathfinding.LocalSpaceGraph component to it. The Pathfinding.LocalSpaceGraph component will store the position and orientation of the object right there are the start and then we can use that information to transform coordinates back to that region of the graph as if the object had not moved at all.

This functionality is only implemented for the RichAI script, however it should not be hard to use the same approach for other movement scripts.

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

override void UpdatePath ()
 Force recalculation of the current path.
- Public Member Functions inherited from RichAI
void Teleport (Vector3 newPosition)
 Instantly moves the agent to the target position.

Public Attributes

LocalSpaceGraph graph
 Root of the object we are moving on.
- Public Attributes inherited from RichAI
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

override void Start ()
 Starts searching for paths.
override void Update ()
 Called every frame.
- Protected Member Functions inherited from RichAI
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 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.
- Protected Member Functions inherited from VersionedMonoBehaviour
virtual int OnUpgradeSerializedData (int version)
 Handle serialization backwards compatibility.

Private Member Functions

void RefreshTransform ()

Additional Inherited Members

- Protected Attributes inherited from RichAI
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>()
- Static Protected Attributes inherited from RichAI
static readonly Color GizmoColorPath = new Color(8.0f/255, 78.0f/255, 194.0f/255)
- Properties inherited from RichAI
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.

Member Function Documentation

void RefreshTransform ( )
override void Start ( )

Starts searching for paths.

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

See Also

Reimplemented from RichAI.

override void Update ( )

Called every frame.

If no rigidbodies are used then all movement happens here

Reimplemented from AIBase.

override 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).

See Also

Reimplemented from RichAI.

Member Data Documentation

Root of the object we are moving on.

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