Class MineBotAI Extends AIPath

Public

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 Methods

OnTargetReached ()

Called when the end of path has been reached.

Public
Start ()

Starts searching for paths.

Public

Public Variables

anim

Animation component.

Public
animationSpeed

Speed relative to velocity with which to play animations.

Public
endOfPathEffect

Effect which will be instantiated when end of path is reached.

Public
sleepVelocity

Minimum velocity for moving.

Public

Inherited Public Members

alwaysDrawGizmos

Draws detailed gizmos constantly in the scene view instead of only when the agent is selected and settings are being modified.

Public
canMove

Enables or disables movement completely.

Public
canSearch

Enables or disables recalculating the path at regular intervals.

Public
centerOffset

Offset along the Y coordinate for the ground raycast start position.

Public
desiredVelocity

Velocity that this agent wants to move with.

Public
destination

Position in the world that this agent should move to.

Public
endReachedDistance

Distance to the end point to consider the end of path to be reached.

Public
FinalizeMovement (nextPosition, nextRotation)

Moves the agent to a position.

Public
GetFeetPosition ()

Position of the base of the character.

Public
gravity

Gravity to use.

Public
groundMask

Layer mask to use for ground placement.

Public
hasPath

True if this agent currently has a path that it follows.

Public
isStopped

Gets or sets if the agent should stop moving.

Public
maxSpeed

Max speed in world units per second.

Public
Move (deltaPosition)

Move the agent.

Public
movementPlane

Plane which this agent is moving in.

Public
MovementUpdate (deltaTime, nextPosition, nextRotation)

Calculate how the character wants to move during this frame.

Public
OnPathComplete (newPath)

Called when a requested path has been calculated.

Public
onSearchPath

Called when the agent recalculates its path.

Public
pathPending

True if a path is currently being calculated.

Public
pickNextWaypointDist

How far the AI looks ahead along the path to determine the point it moves to.

Public
position

Position of the agent.

Public
reachedEndOfPath

True if the agent has reached the end of the current path.

Public
remainingDistance

Remaining distance along the current path to the end of the path.

Public
repathRate

Determines how often the agent will search for new paths (in seconds).

Public
rotation

Rotation of the agent.

Public
rotationIn2D

If true, the forward axis of the character will be along the Y axis instead of the Z axis.

Public
rotationSpeed

Rotation speed in degrees per second.

Public
SearchPath ()

Recalculate the current path.

Public
SimulateRotationTowards (direction, maxDegrees)

Simulates rotating the agent towards the specified direction and returns the new rotation.

Public
slowdownDistance

Distance from the end of the path where the AI will start to slow down.

Public
slowWhenNotFacingTarget

Slow down when not facing the target direction.

Public
steeringTarget

Point on the path which the agent is currently moving towards.

Public
Teleport (newPosition, clearPath=true)

Instantly move the agent to a new position.

Public
updatePosition

Determines if the character's position should be coupled to the Transform's position.

Public
updateRotation

Determines if the character's rotation should be coupled to the Transform's rotation.

Public
velocity

Actual velocity that the agent is moving with.

Public
whenCloseToDestination

What to do when within endReachedDistance units from the destination.

Public

Private/Protected Members

ApplyGravity (deltaTime)

Accelerates the agent downwards.

Protected
Awake ()
Protected
CalculateDeltaToMoveThisFrame (position, distanceToEndOfPath, deltaTime)

Calculates how far to move during a single frame.

Protected
CalculateNextRotation (slowdown, nextRotation)
Protected
CalculatePathRequestEndpoints (start, end)

Outputs the start point and end point of the next automatic path request.

Protected
CancelCurrentPathRequest ()
Protected
ClampToNavmesh (position, positionChanged)

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

Protected
controller

Cached CharacterController component.

Protected
FindComponents ()
Protected
FixedUpdate ()

Called every physics update.

Protected
GizmoColorRaycast
Protected Static Readonly
interpolator

Helper which calculates points along the current path.

Protected
lastDeltaPosition

Amount which the character wants or tried to move with during the last frame.

Protected
lastDeltaTime

Delta time used for movement during the last frame.

Protected
lastRepath

Time when the last path request was started.

Protected
lastTarget

Point for the last spawn of endOfPathEffect.

Protected
MovementUpdateInternal (deltaTime, nextPosition, nextRotation)

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

Protected
OnDisable ()
Protected
OnDrawGizmos ()
Protected
OnDrawGizmosSelected ()
Protected
OnEnable ()

Called when the component is enabled.

Protected
OnUpgradeSerializedData (version, unityThread)

Handle serialization backwards compatibility.

Protected
path

Current path which is followed.

Protected
prevFrame

Last frame index when prevPosition1 was updated.

Protected
prevPosition1

Position of the character at the end of the last frame.

Protected
prevPosition2

Position of the character at the end of the frame before the last frame.

Protected
RaycastPosition (position, lastElevation)

Checks if the character is grounded and prevents ground penetration.

Protected
RepeatTrySearchPath ()

Tries to search for a path every repathRate seconds.

Protected
rigid

Cached Rigidbody component.

Protected
rigid2D

Cached Rigidbody component.

Protected
rvoController

Cached RVOController component.

Protected
seeker

Cached Seeker component.

Protected
shouldRecalculatePath

True if the path should be automatically recalculated as soon as possible.

Protected
simulatedPosition

Position of the agent.

Protected
simulatedRotation

Rotation of the agent.

Protected
SimulateRotationTowards (direction, maxDegrees)

Simulates rotating the agent towards the specified direction and returns the new rotation.

Protected
tr

Cached Transform component.

Protected
Update ()

Called every frame.

Protected
UpdateVelocity ()
Protected
usingGravity

Indicates if gravity is used during this frame.

Protected
velocity2D

Current desired velocity of the agent (does not include local avoidance and physics).

Protected
verticalVelocity

Velocity due to gravity.

Protected
waitingForPathCalculation

Only when the previous path has been calculated should the script consider searching for a new path.

Protected