Class AILerp Extends VersionedMonoBehaviour, IAstarAI

Public

Linearly interpolating movement script.

This movement script will follow the path exactly, it uses linear interpolation to move between the waypoints in the path. This is desirable for some types of games. It also works in 2D.

See

You can see an example of this script in action in the example scene called Example15_2D.

Configuration

Recommended setup for movement along connections

This depends on what type of movement you are aiming for. If you are aiming for movement where the unit follows the path exactly and move only along the graph connections on a grid/point graph. I recommend that you adjust the StartEndModifier on the Seeker component: set the 'Start Point Snapping' field to 'NodeConnection' and the 'End Point Snapping' field to 'SnapToNode'.

Recommended setup for smooth movement

If you on the other hand want smoother movement I recommend setting 'Start Point Snapping' and 'End Point Snapping' to 'ClosestOnNode' and to add the Simple Smooth Modifier to the GameObject as well. Alternatively you can use the Funnel Modifier which works better on navmesh/recast graphs or the RaycastModifier.

You should not combine the Simple Smooth Modifier or the Funnel Modifier with the NodeConnection snapping mode. This may lead to very odd behavior.

You may also want to tweak the rotationSpeed.

Public Methods

FinalizeMovement (nextPosition, nextRotation)

Move the agent.

Public
GetFeetPosition ()
Public
MovementUpdate (deltaTime, nextPosition, nextRotation)

Calculate how the character wants to move during this frame.

Public
OnDisable ()
Public
OnTargetReached ()

The end of the path has been reached.

Public
SearchPath ()

Requests a path to the target.

Public
SetPath (path)

Make the AI follow the specified path.

Public
Teleport (newPosition, clearPath=true)

Instantly move the agent to a new position.

Public

Public Variables

canMove

Enables or disables movement completely.

Public
canSearch

Enables or disables recalculating the path at regular intervals.

Public
destination
Public
enableRotation

If true, the AI will rotate to face the movement direction.

Public
hasPath

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

Public
interpolatePathSwitches

If true, some interpolation will be done when a new path has been calculated.

Public
isStopped

Gets or sets if the agent should stop moving.

Public
onSearchPath

Called when the agent recalculates its path.

Public
orientation

Determines which direction the agent moves in.

Public
pathPending

True if a path is currently being calculated.

Public
position

Position of the agent.

Public
reachedDestination

True if the ai has reached the destination.

Public
reachedEndOfPath

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

Public
remainingDistance

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

Public
repathRate

Determines how often it will search for new paths.

Public
rotation

Rotation of the agent.

Public
rotationSpeed

How quickly to rotate.

Public
speed

Speed in world units.

Public
switchPathInterpolationSpeed

How quickly to interpolate to the new path.

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

Private/Protected Members

AILerp ()
Protected
Awake ()

Initializes reference variables.

Protected
CalculateNextPosition (direction, deltaTime)

Calculate the AI's next position (one frame in the future).

Protected
canMove

Enables or disables movement completely.

Private
canSearch

Enables or disables recalculating the path at regular intervals.

Private
canSearchAgain

Only when the previous path has been returned should a search for a new path be done.

Protected
ClearPath ()

Clears the current path of the agent.

Protected
ConfigureNewPath ()

Finds the closest point on the current path and configures the interpolator.

Protected
ConfigurePathSwitchInterpolation ()
Protected
desiredVelocity
Private
desiredVelocityWithoutLocalAvoidance
Private
height

Height of the agent in world units.

Private
Init ()
Private
interpolator
Protected
lastRepath

Time when the last path request was sent.

Protected
maxSpeed

Max speed in world units per second.

Private
Move (deltaPosition)

Move the agent.

Private
OnEnable ()

Called when the component is enabled.

Protected
OnPathComplete (_p)

Called when a requested path has finished calculation.

Protected
OnUpgradeSerializedData (version, unityThread)

Handle serialization backwards compatibility.

Protected
path

Current path which is followed.

Protected
pathSwitchInterpolationTime

Time since the path was replaced by a new path.

Protected
previousMovementDirection
Protected
previousMovementOrigin

When a new path was returned, the AI was moving along this ray.

Protected
previousPosition1
Private
previousPosition2
Private
radius

Radius of the agent in world units.

Private
Reset ()

Handle serialization backwards compatibility.

Protected
seeker

Cached Seeker component.

Protected
shouldRecalculatePath

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

Protected
simulatedPosition
Private
simulatedRotation
Private
SimulateRotationTowards (direction, deltaTime)
Private
Start ()

Starts searching for paths.

Protected
startHasRun

Holds if the Start function has been run.

Private
steeringTarget

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

Private
targetCompatibility

Required for serialization backward compatibility.

Private
tr

Cached Transform component.

Protected
Update ()
Protected
velocity
Private

Deprecated Members

ForceSearchPath ()

Requests a path to the target.

Public
rotationIn2D

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

Public
target

Target to move towards.

Public