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
ForceSearchPath ()

Requests a path to the target.

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

Calculate how the character wants to move during this frame.

Public
OnDisable ()
Public
OnPathComplete (_p)

Called when a requested path has finished calculation.

Public
OnTargetReached ()

The end of the path has been reached.

Public
SearchPath ()

Requests a path to the target.

Public
Teleport (newPosition, clearPath)

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
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
pathPending
Public
position

Position of the agent.

Public
reachedEndOfPath

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

Public
remainingDistance
Public
repathRate

Determines how often it will search for new paths.

Public
rotation

Rotation of the agent.

Public
rotationIn2D

If true, rotation will only be done along the Z axis so that the Y axis is the forward direction of the character.

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

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
ConfigureNewPath ()

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

Protected
ConfigurePathSwitchInterpolation ()
Protected
desiredVelocity
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
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
RepeatTrySearchPath ()

Tries to search for a path every repathRate seconds.

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

target

Target to move towards.

Public
TrySearchPath ()

Tries to search for a path.

Public