T
- Type of vector, either 2D or 3D, implementing the Vector
interfacepublic class Arrive<T extends com.badlogic.gdx.math.Vector<T>> extends SteeringBehavior<T>
Arrive
behavior moves the agent towards a target position. It is similar to seek but it attempts to arrive at the target
position with a zero velocity.
Arrive
behavior uses two radii. The arrivalTolerance
lets the owner get near enough to the target without
letting small errors keep it in motion. The decelerationRadius
, usually much larger than the previous one, specifies
when the incoming character will begin to slow down. The algorithm calculates an ideal speed for the owner. At the slowing-down
radius, this is equal to its maximum linear speed. At the target point, it is zero (we want to have zero speed when we arrive).
In between, the desired speed is an interpolated intermediate value, controlled by the distance from the target.
The direction toward the target is calculated and combined with the desired speed to give a target velocity. The algorithm
looks at the current velocity of the character and works out the acceleration needed to turn it into the target velocity. We
can't immediately change velocity, however, so the acceleration is calculated based on reaching the target velocity in a fixed
time scale known as timeToTarget
. This is usually a small value; it defaults to 0.1 seconds which is a good starting
point.
Modifier and Type | Field and Description |
---|---|
protected float |
arrivalTolerance
The tolerance for arriving at the target.
|
protected float |
decelerationRadius
The radius for beginning to slow down
|
protected Location<T> |
target
The target to arrive to.
|
protected float |
timeToTarget
The time over which to achieve target speed
|
enabled, limiter, owner
Constructor and Description |
---|
Arrive(Steerable<T> owner)
Creates an
Arrive behavior for the specified owner. |
Arrive(Steerable<T> owner,
Location<T> target)
Creates an
Arrive behavior for the specified owner and target. |
Modifier and Type | Method and Description |
---|---|
protected SteeringAcceleration<T> |
arrive(SteeringAcceleration<T> steering,
T targetPosition) |
protected SteeringAcceleration<T> |
calculateRealSteering(SteeringAcceleration<T> steering)
Calculates the steering acceleration produced by this behavior and writes it to the given steering output.
|
float |
getArrivalTolerance()
Returns the tolerance for arriving at the target.
|
float |
getDecelerationRadius()
Returns the radius for beginning to slow down.
|
Location<T> |
getTarget()
Returns the target to arrive to.
|
float |
getTimeToTarget()
Returns the time over which to achieve target speed.
|
Arrive<T> |
setArrivalTolerance(float arrivalTolerance)
Sets the tolerance for arriving at the target.
|
Arrive<T> |
setDecelerationRadius(float decelerationRadius)
Sets the radius for beginning to slow down.
|
Arrive<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
Arrive<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
Arrive<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
Arrive<T> |
setTarget(Location<T> target)
Sets the target to arrive to.
|
Arrive<T> |
setTimeToTarget(float timeToTarget)
Sets the time over which to achieve target speed.
|
calculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVector
protected Location<T extends com.badlogic.gdx.math.Vector<T>> target
protected float arrivalTolerance
protected float decelerationRadius
protected float timeToTarget
public Arrive(Steerable<T> owner)
Arrive
behavior for the specified owner.owner
- the owner of this behaviorprotected SteeringAcceleration<T> calculateRealSteering(SteeringAcceleration<T> steering)
SteeringBehavior
This method is called by SteeringBehavior.calculateSteering(SteeringAcceleration)
when this steering behavior is enabled.
calculateRealSteering
in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>
steering
- the steering acceleration to be calculated.protected SteeringAcceleration<T> arrive(SteeringAcceleration<T> steering, T targetPosition)
public Arrive<T> setTarget(Location<T> target)
public float getArrivalTolerance()
public Arrive<T> setArrivalTolerance(float arrivalTolerance)
public float getDecelerationRadius()
public Arrive<T> setDecelerationRadius(float decelerationRadius)
public float getTimeToTarget()
public Arrive<T> setTimeToTarget(float timeToTarget)
public Arrive<T> setOwner(Steerable<T> owner)
SteeringBehavior
setOwner
in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>
public Arrive<T> setEnabled(boolean enabled)
SteeringBehavior
setEnabled
in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>
public Arrive<T> setLimiter(Limiter limiter)
setLimiter
in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>