T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class Pursue<T extends com.badlogic.gdx.math.Vector<T>> extends SteeringBehavior<T>
Pursue behavior produces a force that steers the agent towards the evader (the target). Actually it predicts where an
agent will be in time @{code t} and seeks towards that point to intercept it. We did this naturally playing tag as children,
which is why the most difficult tag players to catch were those who kept switching direction, foiling our predictions.
This implementation performs the prediction by assuming the target will continue moving with the same velocity it currently has. This is a reasonable assumption over short distances, and even over longer distances it doesn't appear too stupid. The algorithm works out the distance between character and target and works out how long it would take to get there, at maximum speed. It uses this time interval as its prediction lookahead. It calculates the position of the target if it continues to move with its current velocity. This new position is then used as the target of a standard seek behavior.
If the character is moving slowly, or the target is a long way away, the prediction time could be very large. The target is
less likely to follow the same path forever, so we'd like to set a limit on how far ahead we aim. The algorithm has a
maxPredictionTime for this reason. If the prediction time is beyond this, then the maximum time is used.
| Modifier and Type | Field and Description |
|---|---|
protected float |
maxPredictionTime
The maximum prediction time
|
protected Steerable<T> |
target
The target
|
enabled, limiter, owner| Constructor and Description |
|---|
Pursue(Steerable<T> owner,
Steerable<T> target)
Creates a
Pursue behavior for the specified owner and target. |
Pursue(Steerable<T> owner,
Steerable<T> target,
float maxPredictionTime)
Creates a
Pursue behavior for the specified owner and target. |
| 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.
|
protected float |
getActualMaxLinearAcceleration()
Returns the actual linear acceleration to be applied.
|
float |
getMaxPredictionTime()
Returns the maximum prediction time.
|
Steerable<T> |
getTarget()
Returns the target.
|
Pursue<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
Pursue<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
Pursue<T> |
setMaxPredictionTime(float maxPredictionTime)
Sets the maximum prediction time.
|
Pursue<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
Pursue<T> |
setTarget(Steerable<T> target)
Sets the target.
|
calculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorpublic Pursue(Steerable<T> owner, Steerable<T> target)
Pursue behavior for the specified owner and target. Maximum prediction time defaults to 1 second.owner - the owner of this behavior.target - the target of this behavior.public Pursue(Steerable<T> owner, Steerable<T> target, float maxPredictionTime)
Pursue behavior for the specified owner and target.owner - the owner of this behaviortarget - the target of this behaviormaxPredictionTime - the max time used to predict the target's position assuming it continues to move with its current
velocity.protected float getActualMaxLinearAcceleration()
Evade behavior to invert the
maximum linear acceleration in order to evade the target.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 SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>steering - the steering acceleration to be calculated.public Pursue<T> setTarget(Steerable<T> target)
public float getMaxPredictionTime()
public Pursue<T> setMaxPredictionTime(float maxPredictionTime)
public Pursue<T> setOwner(Steerable<T> owner)
SteeringBehaviorsetOwner in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public Pursue<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public Pursue<T> setLimiter(Limiter limiter)
setLimiter in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>