A* Pathfinding Project
4.0.3
The A* Pathfinding Project for Unity 3D
|
AI controller specifically made for the spider robot. More...
AI controller specifically made for the spider robot.
The spider robot (or mine-bot) which has been copied from the Unity Example Project can have this script attached to be able to pathfind around with animations working properly.
This script should be attached to a parent GameObject however since the original bot has Z+ as up. This component requires Z+ to be forward and Y+ to be up.
It overrides the AIPath class, see that class's documentation for more information on most variables.
Animation is handled by this component. The Animation component refered to in anim should have animations named "awake" and "forward". The forward animation will have it's speed modified by the velocity and scaled by animationSpeed to adjust it to look good. The awake animation will only be sampled at the end frame and will not play.
When the end of path is reached, if the endOfPathEffect is not null, it will be instantiated at the current position. However a check will be done so that it won't spawn effects too close to the previous spawn-point.
Public Member Functions | |
override void | OnTargetReached () |
Called when the end of path has been reached. | |
new void | Start () |
Starts searching for paths. | |
![]() | |
virtual Vector3 | GetFeetPosition () |
void | OnDisable () |
virtual void | OnPathComplete (Path _p) |
Called when a requested path has finished calculation. | |
virtual void | SearchPath () |
Requests a path to the target. | |
float | TrySearchPath () |
Tries to search for a path. | |
Public Attributes | |
Animation | anim |
Animation component. | |
float | animationSpeed = 0.2F |
Speed relative to velocity with which to play animations. | |
GameObject | endOfPathEffect |
Effect which will be instantiated when end of path is reached. | |
float | sleepVelocity = 0.4F |
Minimum velocity for moving. | |
![]() | |
bool | alwaysDrawGizmos |
Draws detailed gizmos constantly in the scene view instead of only when the agent is selected and settings are being modified. | |
bool | canMove = true |
Enables or disables movement. | |
bool | canSearch = true |
Enables or disables searching for paths. | |
float | endReachedDistance = 0.2F |
Distance to the end point to consider the end of path to be reached. | |
float | pickNextWaypointDist = 2 |
Determines within what range it will switch to target the next waypoint in the path. | |
float | repathRate = 0.5F |
Determines how often it will search for new paths. | |
float | rotationSpeed = 360 |
Rotation speed. | |
float | slowdownDistance = 0.6F |
Distance from the target point where the AI will start to slow down. | |
float | speed = 3 |
Maximum velocity. | |
Transform | target |
Target to move towards. | |
![]() | |
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 | Update () |
Called every frame. | |
![]() | |
override void | MovementUpdate (float deltaTime) |
Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not. | |
virtual void | OnEnable () |
Run at start and when reenabled. | |
override int | OnUpgradeSerializedData (int version) |
Handle serialization backwards compatibility. | |
IEnumerator | RepeatTrySearchPath () |
Tries to search for a path every repathRate seconds. | |
![]() | |
void | ApplyGravity (float deltaTime) |
override void | Awake () |
Initializes reference variables. | |
Vector2 | CalculateDeltaToMoveThisFrame (Vector2 position, float distanceToEndOfPath, float deltaTime) |
virtual Vector3 | ClampToNavmesh (Vector3 position) |
Constrains the character's position to lie on the navmesh. | |
virtual void | FixedUpdate () |
Called every physics update. | |
void | Move (Vector3 position3D, Vector3 deltaPosition) |
virtual void | OnDrawGizmos () |
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 Attributes | |
Vector3 | lastTarget |
Point for the last spawn of endOfPathEffect. | |
![]() | |
bool | canSearchAgain = true |
Only when the previous path has been returned should be search for a new path. | |
PathInterpolator | interpolator = new PathInterpolator() |
float | lastRepath = -9999 |
Time when the last path request was sent. | |
Path | path |
Current path which is followed. | |
Vector3 | targetPoint |
Point to where the AI is heading. | |
Vector3 | velocity |
![]() | |
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. | |
Additional Inherited Members | |
![]() | |
static readonly Color | GizmoColorRaycast = new Color(118.0f/255, 206.0f/255, 112.0f/255) |
![]() | |
bool | TargetReached [get, set] |
True if the end of the path has been reached. | |
float | turningSpeed [get, set] |
Rotation speed. | |
|
virtual |
Called when the end of path has been reached.
An effect (endOfPathEffect) is spawned when this function is called However, since paths are recalculated quite often, we only spawn the effect when the current position is some distance away from the previous spawn-point
Reimplemented from AIPath.
|
virtual |
Starts searching for paths.
If you override this function you should in most cases call base.Start () at the start of it.
Reimplemented from AIPath.
|
protectedvirtual |
Called every frame.
If no rigidbodies are used then all movement happens here
Reimplemented from AIBase.
Animation anim |
Animation component.
Should hold animations "awake" and "forward"
float animationSpeed = 0.2F |
Speed relative to velocity with which to play animations.
GameObject endOfPathEffect |
Effect which will be instantiated when end of path is reached.
|
protected |
Point for the last spawn of endOfPathEffect.
float sleepVelocity = 0.4F |
Minimum velocity for moving.