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

DrawGizmos ()
Public
FinalizeMovement (nextPosition, nextRotation)

Move the agent.

Public
GetFeetPosition ()
Public
GetRemainingPath (buffer, stale)

Fills buffer with the remaining path.

Public
MovementUpdate (deltaTime, nextPosition, nextRotation)

Calculate how the character wants to move during this frame.

Public
OnDisable ()
Public
SearchPath ()

Requests a path to the target.

Public
SetPath (path, updateDestinationFromPath=true)

Make the AI follow the specified path.

Public
Teleport (newPosition, clearPath=true)

Instantly move the agent to a new position.

Public

Public Variables

autoRepath

Determines how the agent recalculates its path automatically.

Public
canMove

Enables or disables movement completely.

Public
destination
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 ()
Protected
Awake ()

Initializes reference variables.

Protected
CalculateNextPosition (direction, deltaTime)

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

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
Init ()
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 (migrations, unityThread)
Protected
OnUpgradeSerializedData (migrations, unityThread)

Handle serialization backwards compatibility.

Protected
Reset ()

Handle serialization backwards compatibility.

Protected
SimulateRotationTowards (direction, deltaTime)
Private
Start ()

Starts searching for paths.

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

Required for serialization backward compatibility.

Private
tr

Cached Transform component.

Protected

Deprecated Members

ForceSearchPath ()

Requests a path to the target.

Public
OnTargetReached ()

The end of the path has been reached.

Public
canSearch

Enables or disables recalculating the path at regular intervals.

Public
repathRate

Determines how often it will search for new paths.

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