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

AI controller specifically made for the spider robot. More...

Detailed Description

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.
 
- Public Member Functions inherited from AIPath
Vector3 CalculateVelocity (Vector3 position)
 Current desired velocity of the agent (excluding physics and local avoidance but it includes gravity).
 
override void OnPathComplete (Path newPath)
 Called when a requested path has been calculated.
 
override void Teleport (Vector3 newPosition, bool clearPath=true)
 Instantly move the agent to a new position.
 
- Public Member Functions inherited from AIBase
virtual void FinalizeMovement (Vector3 nextPosition, Quaternion nextRotation)
 Moves the agent to a position.
 
virtual Vector3 GetFeetPosition ()
 Position of the base of the character.
 
virtual void Move (Vector3 deltaPosition)
 Move the agent.
 
void MovementUpdate (float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation)
 Calculate how the character wants to move during this frame.
 
virtual void SearchPath ()
 Recalculate the current path.
 
Quaternion SimulateRotationTowards (Vector3 direction, float maxDegrees)
 Simulates rotating the agent towards the specified direction and returns the new rotation.
 
- Public Member Functions inherited from IAstarAI
void FinalizeMovement (Vector3 nextPosition, Quaternion nextRotation)
 Move the agent.
 
void Move (Vector3 deltaPosition)
 Move the agent.
 
void MovementUpdate (float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation)
 Calculate how the character wants to move during this frame.
 
void SearchPath ()
 Recalculate the current path.
 
void Teleport (Vector3 newPosition, bool clearPath=true)
 Instantly move the agent to a new position.
 

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.
 
- Public Attributes inherited from AIPath
bool alwaysDrawGizmos
 Draws detailed gizmos constantly in the scene view instead of only when the agent is selected and settings are being modified.
 
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 rotationSpeed = 360
 Rotation speed.
 
float slowdownDistance = 0.6F
 Distance from the target point where the AI will start to slow down.
 
bool slowWhenNotFacingTarget = true
 Slow down when not facing the target direction.
 
CloseToDestinationMode whenCloseToDestination = CloseToDestinationMode.Stop
 What to do when within endReachedDistance units from the destination.
 
- Public Attributes inherited from AIBase
bool canMove = true
 Enables or disables movement completely.
 
bool canSearch = true
 Enables or disables recalculating the path at regular intervals.
 
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.
 
float maxSpeed = 1
 Max speed in world units per second.
 
IMovementPlane movementPlane = GraphTransform.identityTransform
 Plane which this agent is moving in.
 
float repathRate = 0.5f
 Determines how often the agent will search for new paths (in seconds).
 
bool rotationIn2D = false
 If true, the forward axis of the character will be along the Y axis instead of the Z axis.
 
bool updatePosition = true
 Determines if the character's position should be coupled to the Transform's position.
 
bool updateRotation = true
 Determines if the character's rotation should be coupled to the Transform's rotation.
 

Protected Member Functions

override void Update ()
 Called every frame.
 
- Protected Member Functions inherited from AIPath
virtual void CalculateNextRotation (float slowdown, out Quaternion nextRotation)
 
override void MovementUpdateInternal (float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation)
 Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not.
 
override void OnDisable ()
 
override int OnUpgradeSerializedData (int version, bool unityThread)
 Handle serialization backwards compatibility.
 
- Protected Member Functions inherited from AIBase
 AIBase ()
 
void ApplyGravity (float deltaTime)
 Accelerates the agent downwards.
 
Vector2 CalculateDeltaToMoveThisFrame (Vector2 position, float distanceToEndOfPath, float deltaTime)
 Calculates how far to move during a single frame.
 
virtual void CalculatePathRequestEndpoints (out Vector3 start, out Vector3 end)
 Outputs the start point and end point of the next automatic path request.
 
void CancelCurrentPathRequest ()
 
virtual Vector3 ClampToNavmesh (Vector3 position, out bool positionChanged)
 Constrains the character's position to lie on the navmesh.
 
virtual void FindComponents ()
 
virtual void FixedUpdate ()
 Called every physics update.
 
virtual void OnDrawGizmos ()
 
virtual void OnDrawGizmosSelected ()
 
virtual void OnEnable ()
 Called when the component is enabled.
 
Vector3 RaycastPosition (Vector3 position, float lastElevation)
 Checks if the character is grounded and prevents ground penetration.
 
IEnumerator RepeatTrySearchPath ()
 Tries to search for a path every repathRate seconds.
 
Quaternion SimulateRotationTowards (Vector2 direction, float maxDegrees)
 Simulates rotating the agent towards the specified direction and returns the new rotation.
 
void UpdateVelocity ()
 
- Protected Member Functions inherited from VersionedMonoBehaviour
virtual void Awake ()
 

Protected Attributes

Vector3 lastTarget
 Point for the last spawn of endOfPathEffect.
 
- Protected Attributes inherited from AIPath
PathInterpolator interpolator = new PathInterpolator()
 Helper which calculates points along the current path.
 
Path path
 Current path which is followed.
 
- Protected Attributes inherited from AIBase
CharacterController controller
 Cached CharacterController component.
 
Vector2 lastDeltaPosition
 Amount which the character wants or tried to move with during the last frame.
 
float lastDeltaTime
 Delta time used for movement during the last frame.
 
float lastRepath = float.NegativeInfinity
 Time when the last path request was started.
 
int prevFrame
 Last frame index when prevPosition1 was updated.
 
Vector3 prevPosition1
 Position of the character at the end of the last frame.
 
Vector3 prevPosition2
 Position of the character at the end of the frame before the last frame.
 
Rigidbody rigid
 Cached Rigidbody component.
 
Rigidbody2D rigid2D
 Cached Rigidbody component.
 
RVOController rvoController
 Cached RVOController component.
 
Seeker seeker
 Cached Seeker component.
 
Vector3 simulatedPosition
 Position of the agent.
 
Quaternion simulatedRotation
 Rotation of the agent.
 
Transform tr
 Cached Transform component.
 
Vector2 velocity2D
 Current desired velocity of the agent (does not include local avoidance and physics).
 
float verticalVelocity
 Velocity due to gravity.
 
bool waitingForPathCalculation = false
 Only when the previous path has been calculated should the script consider searching for a new path.
 

Additional Inherited Members

- Static Protected Attributes inherited from AIBase
static readonly Color GizmoColorRaycast = new Color(118.0f/255, 206.0f/255, 112.0f/255)
 
- Properties inherited from AIPath
bool IAstarAI. canMove [get, set]
 Enables or disables movement completely.
 
bool IAstarAI. canSearch [get, set]
 Enables or disables recalculating the path at regular intervals.
 
bool hasPath [get]
 True if this agent currently has a path that it follows.
 
float IAstarAI. maxSpeed [get, set]
 Max speed in world units per second.
 
bool pathPending [get]
 True if a path is currently being calculated.
 
float remainingDistance [get]
 Remaining distance along the current path to the end of the path.
 
float speed [get, set]
 Maximum speed in world units per second.
 
Vector3 steeringTarget [get]
 Point on the path which the agent is currently moving towards.
 
Vector3 targetDirection [get]
 Direction that the agent wants to move in (excluding physics and local avoidance).
 
bool TargetReached [get]
 True if the end of the path has been reached.
 
bool targetReached [get, set]
 True if the agent has reached the end of the current path.
 
float turningSpeed [get, set]
 Rotation speed.
 

Member Function Documentation

override void OnTargetReached ( )
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.

new void Start ( )
virtual

Starts searching for paths.

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

See Also
Init

Reimplemented from AIBase.

override void Update ( )
protectedvirtual

Called every frame.

If no rigidbodies are used then all movement happens here.

Reimplemented from AIBase.

Member Data Documentation

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.

See Also
OnTargetReached
Vector3 lastTarget
protected

Point for the last spawn of endOfPathEffect.

float sleepVelocity = 0.4F

Minimum velocity for moving.


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