T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class PrioritySteering<T extends com.badlogic.gdx.math.Vector<T>> extends SteeringBehavior<T>
PrioritySteering behavior iterates through the behaviors and returns the first non zero steering. It makes sense
since certain steering behaviors only request an acceleration in particular conditions. Unlike Seek or Evade,
which always produce an acceleration, RaycastObstacleAvoidance, CollisionAvoidance, Separation,
Hide and Arrive will suggest no acceleration in many cases. But when these behaviors do suggest an
acceleration, it is unwise to ignore it. An obstacle avoidance behavior, for example, should be honored immediately to avoid
the crash.
Typically the behaviors of a PrioritySteering are arranged in groups with regular blending weights, see
BlendedSteering. These groups are then placed in priority order to let the steering system consider each group in turn.
It blends the steering behaviors in the current group together. If the total result is very small (less than some small, but
adjustable, parameter), then it is ignored and the next group is considered. It is best not to check against zero directly,
because numerical instability in calculations can mean that a zero value is never reached for some steering behaviors. Using a
small constant value (conventionally called epsilon) avoids this problem. When a group is found with a result that isn't
small, its result is used to steer the agent.
For instance, a pursuing agent working in a team may have three priorities:
In a different scenario, if the character is about to crash into a wall, the first group will return an acceleration that will help avoid the crash. The character will carry out this acceleration immediately, and the steering behaviors in the other groups won't be considered.
Usually PrioritySteering gives you a good compromise between speed and accuracy.
| Modifier and Type | Field and Description |
|---|---|
protected com.badlogic.gdx.utils.Array<SteeringBehavior<T>> |
behaviors
The list of steering behaviors in priority order.
|
protected float |
epsilon
The threshold of the steering acceleration magnitude below which a steering behavior is considered to have given no output.
|
protected int |
selectedBehaviorIndex
The index of the behavior whose acceleration has been returned by the last evaluation of this priority steering.
|
enabled, limiter, owner| Constructor and Description |
|---|
PrioritySteering(Steerable<T> owner)
Creates a
PrioritySteering behavior for the specified owner. |
PrioritySteering(Steerable<T> owner,
float epsilon)
Creates a
PrioritySteering behavior for the specified owner and threshold. |
| Modifier and Type | Method and Description |
|---|---|
PrioritySteering<T> |
add(SteeringBehavior<T> behavior)
Adds the specified behavior to the priority list.
|
protected SteeringAcceleration<T> |
calculateRealSteering(SteeringAcceleration<T> steering)
Calculates the steering acceleration produced by this behavior and writes it to the given steering output.
|
float |
getEpsilon()
Returns the threshold of the steering acceleration magnitude below which a steering behavior is considered to have given no
output.
|
int |
getSelectedBehaviorIndex()
Returns the index of the behavior whose acceleration has been returned by the last evaluation of this priority steering; -1
otherwise.
|
PrioritySteering<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
PrioritySteering<T> |
setEpsilon(float epsilon)
Sets the threshold of the steering acceleration magnitude below which a steering behavior is considered to have given no
output.
|
PrioritySteering<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
PrioritySteering<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
calculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected float epsilon
protected com.badlogic.gdx.utils.Array<SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>> behaviors
protected int selectedBehaviorIndex
public PrioritySteering(Steerable<T> owner)
PrioritySteering behavior for the specified owner. The threshold is set to 0.001.owner - the owner of this behaviorpublic PrioritySteering(Steerable<T> owner, float epsilon)
PrioritySteering behavior for the specified owner and threshold.owner - the owner of this behaviorepsilon - the threshold of the steering acceleration magnitude below which a steering behavior is considered to have
given no outputpublic PrioritySteering<T> add(SteeringBehavior<T> behavior)
behavior - the behavior to addprotected 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 int getSelectedBehaviorIndex()
public float getEpsilon()
public PrioritySteering<T> setEpsilon(float epsilon)
epsilon - the epsilon to setpublic PrioritySteering<T> setOwner(Steerable<T> owner)
SteeringBehaviorsetOwner in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public PrioritySteering<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public PrioritySteering<T> setLimiter(Limiter limiter)
PrioritySteering needs no limiter at all as it simply returns
the first non zero steering acceleration.setLimiter in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>