T - Type of vector, either 2D or 3D, implementing the Vector interfaceP - Type of path parameter implementing the Path.PathParam interfacepublic class FollowPath<T extends com.badlogic.gdx.math.Vector<T>,P extends Path.PathParam> extends Arrive<T>
FollowPath behavior produces a linear acceleration that moves the agent along the given path. First it calculates the
agent location based on the specified prediction time. Then it works out the position of the internal target based on the
location just calculated and the shape of the path. It finally uses seek behavior to move the owner towards the
internal target position. However, if the path is open arrive behavior is used to approach path's extremities
when they are far less than the deceleration radius from the internal target position.
For complex paths with sudden changes of direction the predictive behavior (i.e., with prediction time greater than 0) can appear smoother than the non-predictive one (i.e., with no prediction time). However, predictive path following has the downside of cutting corners when some sections of the path come close together. This cutting-corner attitude can make the character miss a whole section of the path. This might not be what you want if, for example, the path represents a patrol route.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
arriveEnabled
The flag indicating whether to use
Arrive behavior to approach the end of an open path. |
protected Path<T,P> |
path
The path to follow
|
protected float |
pathOffset
The distance along the path to generate the target.
|
protected P |
pathParam
The current position on the path
|
protected float |
predictionTime
The time in the future to predict the owner's position.
|
arrivalTolerance, decelerationRadius, target, timeToTargetenabled, limiter, owner| Constructor and Description |
|---|
FollowPath(Steerable<T> owner,
Path<T,P> path)
Creates a non-predictive
FollowPath behavior for the specified owner and path. |
FollowPath(Steerable<T> owner,
Path<T,P> path,
float pathOffset)
Creates a non-predictive
FollowPath behavior for the specified owner, path and path offset. |
FollowPath(Steerable<T> owner,
Path<T,P> path,
float pathOffset,
float predictionTime)
Creates a
FollowPath behavior for the specified owner, path, path offset, maximum linear acceleration and prediction
time. |
| Modifier and Type | Method and Description |
|---|---|
protected SteeringAcceleration<T> |
calculateRealSteering(SteeringAcceleration<T> steering)
Calculates the steering acceleration produced by this behavior and writes it to the given steering output.
|
T |
getInternalTargetPosition()
Returns the current position of the internal target.
|
Path<T,P> |
getPath()
Returns the path to follow
|
float |
getPathOffset()
Returns the path offset.
|
P |
getPathParam()
Returns the current path parameter.
|
float |
getPredictionTime()
Returns the prediction time.
|
boolean |
isArriveEnabled()
Returns the flag indicating whether to use
Arrive behavior to approach the end of an open path. |
FollowPath<T,P> |
setArrivalTolerance(float arrivalTolerance)
Sets the tolerance for arriving at the target.
|
FollowPath<T,P> |
setArriveEnabled(boolean arriveEnabled)
Sets the flag indicating whether to use
Arrive behavior to approach the end of an open path. |
FollowPath<T,P> |
setDecelerationRadius(float decelerationRadius)
Sets the radius for beginning to slow down.
|
FollowPath<T,P> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
FollowPath<T,P> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
FollowPath<T,P> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
FollowPath<T,P> |
setPath(Path<T,P> path)
Sets the path followed by this behavior.
|
FollowPath<T,P> |
setPathOffset(float pathOffset)
Sets the path offset to generate the target.
|
FollowPath<T,P> |
setPredictionTime(float predictionTime)
Sets the prediction time.
|
FollowPath<T,P> |
setTarget(Location<T> target)
Sets the target to arrive to.
|
FollowPath<T,P> |
setTimeToTarget(float timeToTarget)
Sets the time over which to achieve target speed.
|
arrive, getArrivalTolerance, getDecelerationRadius, getTarget, getTimeToTargetcalculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected Path<T extends com.badlogic.gdx.math.Vector<T>,P extends Path.PathParam> path
protected float pathOffset
protected P extends Path.PathParam pathParam
protected boolean arriveEnabled
Arrive behavior to approach the end of an open path. It defaults to true.protected float predictionTime
public FollowPath(Steerable<T> owner, Path<T,P> path)
FollowPath behavior for the specified owner and path.owner - the owner of this behaviorpath - the path to be followed by the owner.public FollowPath(Steerable<T> owner, Path<T,P> path, float pathOffset)
FollowPath behavior for the specified owner, path and path offset.owner - the owner of this behaviorpath - the path to be followed by the ownerpathOffset - the distance along the path to generate the target. Can be negative if the owner is to move along the
reverse direction.public FollowPath(Steerable<T> owner, Path<T,P> path, float pathOffset, float predictionTime)
FollowPath behavior for the specified owner, path, path offset, maximum linear acceleration and prediction
time.owner - the owner of this behaviorpath - the path to be followed by the ownerpathOffset - the distance along the path to generate the target. Can be negative if the owner is to move along the
reverse direction.predictionTime - the time in the future to predict the owner's position. Can be 0 for non-predictive path following.protected SteeringAcceleration<T> calculateRealSteering(SteeringAcceleration<T> steering)
SteeringBehavior
This method is called by SteeringBehavior.calculateSteering(SteeringAcceleration) when this steering behavior is enabled.
calculateRealSteering in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>steering - the steering acceleration to be calculated.public FollowPath<T,P> setPath(Path<T,P> path)
path - the path to setpublic float getPathOffset()
public boolean isArriveEnabled()
Arrive behavior to approach the end of an open path.public float getPredictionTime()
public FollowPath<T,P> setPredictionTime(float predictionTime)
predictionTime - the predictionTime to setpublic FollowPath<T,P> setArriveEnabled(boolean arriveEnabled)
Arrive behavior to approach the end of an open path. It defaults to
true.arriveEnabled - the flag value to setpublic FollowPath<T,P> setPathOffset(float pathOffset)
pathOffset - the pathOffset to setpublic P getPathParam()
public T getInternalTargetPosition()
public FollowPath<T,P> setOwner(Steerable<T> owner)
SteeringBehaviorpublic FollowPath<T,P> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public FollowPath<T,P> setLimiter(Limiter limiter)
setLimiter in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public FollowPath<T,P> setTarget(Location<T> target)
Arrivepublic FollowPath<T,P> setArrivalTolerance(float arrivalTolerance)
ArrivesetArrivalTolerance in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public FollowPath<T,P> setDecelerationRadius(float decelerationRadius)
ArrivesetDecelerationRadius in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public FollowPath<T,P> setTimeToTarget(float timeToTarget)
ArrivesetTimeToTarget in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>