T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class CollisionAvoidance<T extends com.badlogic.gdx.math.Vector<T>> extends GroupBehavior<T> implements Proximity.ProximityCallback<T>
CollisionAvoidance behavior steers the owner to avoid obstacles lying in its path. An obstacle is any object that can be
approximated by a circle (or sphere, if you are working in 3D).
This implementation uses collision prediction working out the closest approach of two agents and determining if their distance at this point is less than the sum of their bounding radius. For avoiding groups of characters, averaging positions and velocities do not work well with this approach. Instead, the algorithm needs to search for the character whose closest approach will occur first and to react to this character only. Once this imminent collision is avoided, the steering behavior can then react to more distant characters.
This algorithm works well with small and/or moving obstacles whose shape can be approximately represented by a center and a radius.
proximityenabled, limiter, owner| Constructor and Description |
|---|
CollisionAvoidance(Steerable<T> owner,
Proximity<T> proximity)
Creates a
CollisionAvoidance behavior for the specified owner and proximity. |
| 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.
|
boolean |
reportNeighbor(Steerable<T> neighbor)
The callback method used to report a neighbor.
|
CollisionAvoidance<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
CollisionAvoidance<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
CollisionAvoidance<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
getProximity, setProximitycalculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected 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 boolean reportNeighbor(Steerable<T> neighbor)
Proximity.ProximityCallbackreportNeighbor in interface Proximity.ProximityCallback<T extends com.badlogic.gdx.math.Vector<T>>neighbor - the reported neighbor.true if the given neighbor is valid; false otherwise.public CollisionAvoidance<T> setOwner(Steerable<T> owner)
SteeringBehaviorsetOwner in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public CollisionAvoidance<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public CollisionAvoidance<T> setLimiter(Limiter limiter)
setLimiter in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>