Class LegacyAIPath Extends AIPath
AI for following paths.
This AI is the default movement script which comes with the A* Pathfinding Project. It is in no way required by the rest of the system, so feel free to write your own. But I hope this script will make it easier to set up movement for the characters in your game. This script is not written for high performance, so I do not recommend using it for large groups of units.
This script will try to follow a target transform, in regular intervals, the path to that target will be recalculated. It will on FixedUpdate try to move towards the next point in the path. However it will only move in the forward direction, but it will rotate around it's Y-axis to make it reach the target.
Quick overview of the variables
In the inspector in Unity, you will see a bunch of variables. You can view detailed information further down, but here's a quick overview.
The repathRate determines how often it will search for new paths, if you have fast moving targets, you might want to set it to a lower value.
The target variable is where the AI will try to move, it can be a point on the ground where the player has clicked in an RTS for example. Or it can be the player object in a zombie game.
The speed is self-explanatory, so is turningSpeed, however slowdownDistance might require some explanation. It is the approximate distance from the target where the AI will start to slow down. Note that this doesn't only affect the end point of the path but also any intermediate points, so be sure to set forwardLook and pickNextWaypointDist to a higher value than this.
pickNextWaypointDist is simply determines within what range it will switch to target the next waypoint in the path.
forwardLook will try to calculate an interpolated target point on the current segment in the path so that it has a distance of forwardLook from the AI
Below is an image illustrating several variables as well as some internal ones, but which are relevant for understanding how it works. Note that the forwardLook range will not match up exactly with the target point practically, even though that's the goal. This script has many movement fallbacks. If it finds a NavmeshController, it will use that, otherwise it will look for a character controller, then for a rigidbody and if it hasn't been able to find any it will use Transform.Translate which is guaranteed to always work.
Deprecated
Use the AIPath class instead. This class only exists for compatibility reasons.
Public Variables
Do a closest point on path check when receiving path callback.
Target point is Interpolated on the current segment in the path so that it has a distance of forwardLook from the AI.
Inherited Public Members
Moves the agent to a position.
Looks for any attached components like RVOController and CharacterController etc.
Position of the base of the character.
Fills buffer with the remaining path.
Move the agent.
Calculate how the character wants to move during this frame.
The end of the path has been reached.
Recalculate the current path.
Make the AI follow the specified path.
Simulates rotating the agent towards the specified direction and returns the new rotation.
Instantly move the agent to a new position.
Draws detailed gizmos constantly in the scene view instead of only when the agent is selected and settings are being modified.
Determines how the agent recalculates its path automatically.
Enables or disables movement completely.
Ensure that the character is always on the traversable surface of the navmesh.
Velocity that this agent wants to move with.
Velocity that this agent wants to move with before taking local avoidance into account.
Position in the world that this agent should move to.
If true, the AI will rotate to face the movement direction.
End point of path the agent is currently following.
Distance to the end point to consider the end of path to be reached.
Gravity to use.
Layer mask to use for ground placement.
True if this agent currently has a path that it follows.
Height of the agent in world units.
Gets or sets if the agent should stop moving.
How quickly the agent accelerates.
Max speed in world units per second.
Plane which this agent is moving in.
Called when the agent recalculates its path.
Determines which direction the agent moves in.
True if a path is currently being calculated.
How far the AI looks ahead along the path to determine the point it moves to.
Position of the agent.
Prevent the velocity from being too far away from the forward direction of the character.
Radius of the agent in world units.
True if the agent has reached the end of the current path.
Approximate remaining distance along the current path to the end of the path.
Rotation of the agent.
Rotation speed in degrees per second.
Controls if the agent slows down to a stop if the area around the destination is crowded.
Slow down when not facing the target direction.
Distance from the end of the path where the AI will start to slow down.
Point on the path which the agent is currently moving towards.
Determines if the character's position should be coupled to the Transform's position.
Determines if the character's rotation should be coupled to the Transform's rotation.
Actual velocity that the agent is moving with.
Private/Protected Members
Accelerates the agent downwards.
Calculates how far to move during a single frame.
Outputs the start point and end point of the next automatic path request.
Calculates target point from the current line segment.
Calculates desired velocity.
Constrains the character's position to lie on the navmesh.
Clears the current path of the agent.
Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not.
Called when the component is enabled.
Called when a requested path has finished calculation.
Called every frame.
Handle serialization backwards compatibility.
Checks if the character is grounded and prevents ground penetration.
Handle serialization backwards compatibility.
Rotates in the specified direction.
Simulates rotating the agent towards the specified direction and returns the new rotation.
Starts searching for paths.
Cached CharacterController component.
Current index in the path which is current target.
Represents the current steering target for the agent.
Helper which calculates points along the current path.
Amount which the character wants or tried to move with during the last frame.
Delta time used for movement during the last frame.
Hit info from the last raycast done for ground placement.
Time when the last path request was started.
Current path which is followed.
Position of the character at the end of the last frame.
Position of the character at the end of the frame before the last frame.
Cached Rigidbody component.
Cached Rigidbody component.
Cached RVOController component.
True if the path should be automatically recalculated as soon as possible.
Position of the agent.
Rotation of the agent.
Relative direction to where the AI is heading.
Cached Transform component.
Indicates if gravity is used during this frame.
Current desired velocity of the agent (does not include local avoidance and physics).
Velocity due to gravity.
Only when the previous path has been calculated should the script consider searching for a new path.