T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class RaycastObstacleAvoidance<T extends com.badlogic.gdx.math.Vector<T>> extends SteeringBehavior<T>
RaycastObstacleAvoidance the moving agent (the owner) casts one or more rays out in the direction of its
motion. If these rays collide with an obstacle, then a target is created that will avoid the collision, and the owner does a
basic seek on this target. Typically, the rays extend a short distance ahead of the character (usually a distance corresponding
to a few seconds of movement).
This behavior is especially suitable for large-scale obstacles like walls.
You should use the RayConfiguration more suitable for your game environment. Some basic ray configurations are provided
by the framework: SingleRayConfiguration, ParallelSideRayConfiguration and
CentralRayWithWhiskersConfiguration. There are no hard and fast rules as to which configuration is better. Each has its
own particular idiosyncrasies. A single ray with short whiskers is often the best initial configuration to try but can make it
impossible for the character to move down tight passages. The single ray configuration is useful in concave environments but
grazes convex obstacles. The parallel configuration works well in areas where corners are highly obtuse but is very susceptible
to the corner trap.
The corner trap
All the basic configurations for multi-ray obstacle avoidance can suffer from a crippling problem
with acute angled corners (any convex corner, in fact, but it is more prevalent with acute angles). Consider a character with
two parallel rays that is going towards a corner. As soon as its left ray is colliding with the wall near the corner, the
steering behavior will turn it to the left to avoid the collision. Immediately, the right ray will then be colliding the other
side of the corner, and the steering behavior will turn the character to the right. The character will repeatedly collide both
sides of the corner in rapid succession. It will appear to home into the corner directly, until it slams into the wall. It will
be unable to free itself from the trap.
The fan structure, with a wide enough fan angle, alleviates this problem. Often, there is a trade-off, however, between avoiding the corner trap with a large fan angle and keeping the angle small to allow the character to access small passages. At worst, with a fan angle near PI radians, the character will not be able to respond quickly enough to collisions detected on its side rays and will still graze against walls. There are two approaches that work well and represent the most practical solutions to the problem:
| Modifier and Type | Field and Description |
|---|---|
protected float |
distanceFromBoundary
The minimum distance to a wall, i.e.
|
protected RaycastCollisionDetector<T> |
raycastCollisionDetector
The collision detector
|
protected RayConfiguration<T> |
rayConfiguration
The inputRay configuration
|
enabled, limiter, owner| Constructor and Description |
|---|
RaycastObstacleAvoidance(Steerable<T> owner)
Creates a
RaycastObstacleAvoidance behavior. |
RaycastObstacleAvoidance(Steerable<T> owner,
RayConfiguration<T> rayConfiguration)
Creates a
RaycastObstacleAvoidance behavior. |
RaycastObstacleAvoidance(Steerable<T> owner,
RayConfiguration<T> rayConfiguration,
RaycastCollisionDetector<T> raycastCollisionDetector)
Creates a
RaycastObstacleAvoidance behavior. |
RaycastObstacleAvoidance(Steerable<T> owner,
RayConfiguration<T> rayConfiguration,
RaycastCollisionDetector<T> raycastCollisionDetector,
float distanceFromBoundary)
Creates a
RaycastObstacleAvoidance behavior. |
| 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.
|
float |
getDistanceFromBoundary()
Returns the distance from boundary, i.e.
|
RaycastCollisionDetector<T> |
getRaycastCollisionDetector()
Returns the raycast collision detector of this behavior.
|
RayConfiguration<T> |
getRayConfiguration()
Returns the ray configuration of this behavior.
|
RaycastObstacleAvoidance<T> |
setDistanceFromBoundary(float distanceFromBoundary)
Sets the distance from boundary, i.e.
|
RaycastObstacleAvoidance<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
RaycastObstacleAvoidance<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
RaycastObstacleAvoidance<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
RaycastObstacleAvoidance<T> |
setRaycastCollisionDetector(RaycastCollisionDetector<T> raycastCollisionDetector)
Sets the raycast collision detector of this behavior.
|
RaycastObstacleAvoidance<T> |
setRayConfiguration(RayConfiguration<T> rayConfiguration)
Sets the ray configuration of this behavior.
|
calculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected RayConfiguration<T extends com.badlogic.gdx.math.Vector<T>> rayConfiguration
protected RaycastCollisionDetector<T extends com.badlogic.gdx.math.Vector<T>> raycastCollisionDetector
protected float distanceFromBoundary
public RaycastObstacleAvoidance(Steerable<T> owner)
RaycastObstacleAvoidance behavior.owner - the owner of this behaviorpublic RaycastObstacleAvoidance(Steerable<T> owner, RayConfiguration<T> rayConfiguration)
RaycastObstacleAvoidance behavior.owner - the owner of this behaviorrayConfiguration - the ray configurationpublic RaycastObstacleAvoidance(Steerable<T> owner, RayConfiguration<T> rayConfiguration, RaycastCollisionDetector<T> raycastCollisionDetector)
RaycastObstacleAvoidance behavior.owner - the owner of this behaviorrayConfiguration - the ray configurationraycastCollisionDetector - the collision detectorpublic RaycastObstacleAvoidance(Steerable<T> owner, RayConfiguration<T> rayConfiguration, RaycastCollisionDetector<T> raycastCollisionDetector, float distanceFromBoundary)
RaycastObstacleAvoidance behavior.owner - the owner of this behaviorrayConfiguration - the ray configurationraycastCollisionDetector - the collision detectordistanceFromBoundary - the minimum distance to a wall (i.e., how far to avoid collision).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 RayConfiguration<T> getRayConfiguration()
public RaycastObstacleAvoidance<T> setRayConfiguration(RayConfiguration<T> rayConfiguration)
rayConfiguration - the ray configuration to setpublic RaycastCollisionDetector<T> getRaycastCollisionDetector()
public RaycastObstacleAvoidance<T> setRaycastCollisionDetector(RaycastCollisionDetector<T> raycastCollisionDetector)
raycastCollisionDetector - the raycast collision detector to setpublic float getDistanceFromBoundary()
public RaycastObstacleAvoidance<T> setDistanceFromBoundary(float distanceFromBoundary)
distanceFromBoundary - the distanceFromBoundary to setpublic RaycastObstacleAvoidance<T> setOwner(Steerable<T> owner)
SteeringBehaviorsetOwner in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public RaycastObstacleAvoidance<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public RaycastObstacleAvoidance<T> setLimiter(Limiter limiter)
setLimiter in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>