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.

GetRemainingPath (buffer, [partsBuffer], stale)

Fills buffer with the remaining path.

MovementUpdate (deltaTime, nextPosition, nextRotation)

Calculate how the character wants to move during this frame.

Requests a path to the target.

SetPath (path, updateDestinationFromPath=true)

Make the AI follow the specified path.

Teleport (newPosition, clearPath=true)

Instantly move the agent to a new position.

Public Variables

autoRepath

Determines how the agent recalculates its path automatically.

Public
canMove

Enables or disables movement completely.

Public
destination

Position in the world that this agent should move to.

Public
enableRotation

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

Public
endOfPath

End point of path the agent is currently following.

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
movementPlane

The plane the agent is moving in.

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

Approximate remaining distance along the current path to the end of the path.

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
velocity

Actual velocity that the agent is moving with.

Public

Private/Protected Members

AILerp ()
Awake ()

Initializes reference variables.

CalculateNextPosition (direction, deltaTime)

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

Clears the current path of the agent.

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

Init ()
Move (deltaPosition)

Move the agent.

Called when the component is enabled.

Called when a requested path has finished calculation.

OnUpgradeSerializedData (migrations, unityThread)

Reset ()

Handle serialization backwards compatibility.

SimulateRotationTowards (direction, deltaTime)
Start ()

Starts searching for paths.

Update ()
UpgradeSerializedData (isUnityThread)
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
canSearchCompability
Private
desiredVelocity

Velocity that this agent wants to move with.

Private
desiredVelocityWithoutLocalAvoidance

Velocity that this agent wants to move with before taking local avoidance into account.

Private
height

Height of the agent in world units.

Private
interpolator
Protected
interpolatorPath
Protected
maxSpeed

Max speed in world units per second.

Private
onPathComplete

Cached delegate for the OnPathComplete method.

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
repathRateCompatibility
Private
seeker

Cached Seeker component.

Protected
shouldRecalculatePath

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

Protected
simulatedPosition
Private
simulatedRotation
Private
startHasRun

Holds if the Start function has been run.

Private
steeringTarget

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

Private
tr

Cached Transform component.

Protected

Deprecated Members

The end of the path has been reached.

canSearch

Enables or disables recalculating the path at regular intervals.

Public
repathRate

Determines how often it will search for new paths.

Public