T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class Hide<T extends com.badlogic.gdx.math.Vector<T>> extends Arrive<T> implements Proximity.ProximityCallback<T>
You can use this behavior not only for situations where you require a non-player character (NPC) to hide from the player, like find cover when fired at, but also in situations where you would like an NPC to sneak up on a player. For example, you can create an NPC capable of stalking a player through a gloomy forest, darting from tree to tree.
It's worth mentioning that since this behavior can produce no steering acceleration it is commonly used with
PrioritySteering. For instance, to make the owner go away from the target if there are no obstacles nearby to hide
behind, just use Hide and Evade behaviors with this priority order.
There are a few interesting modifications you might want to make to this behavior:
FieldOfViewProximity you can allow the owner to hide only if the target is within its field of view. This
tends to produce unsatisfactory performance though, because the owner starts to act like a child hiding from monsters beneath
the bed sheets, something like "if you can't see it, then it can't see you" effect making the owner look dumb. This can be
countered slightly though by adding in a time effect so that the owner will hide if the target is visible or if it has seen the
target within the last N seconds. This gives it a sort of memory and produces reasonable-looking behavior.getHidingPosition(T, float, T).| Modifier and Type | Field and Description |
|---|---|
protected float |
distanceFromBoundary
The distance from the boundary of the obstacle behind which to hide.
|
protected Proximity<T> |
proximity
The proximity to find nearby obstacles.
|
arrivalTolerance, decelerationRadius, target, timeToTargetenabled, limiter, owner| Constructor and Description |
|---|
Hide(Steerable<T> owner)
Creates an
Hide behavior for the specified owner. |
Hide(Steerable<T> owner,
Location<T> target)
Creates a
Hide behavior for the specified owner and target. |
Hide(Steerable<T> owner,
Location<T> target,
Proximity<T> proximity)
Creates a
Hide behavior for the specified owner, target 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.
|
float |
getDistanceFromBoundary()
Returns the distance from the boundary of the obstacle behind which to hide.
|
protected T |
getHidingPosition(T obstaclePosition,
float obstacleRadius,
T targetPosition)
Given the position of a target and the position and radius of an obstacle, this method calculates a position
distanceFromBoundary away from the object's bounding radius and directly opposite the target. |
Proximity<T> |
getProximity()
Returns the proximity used to find nearby obstacles.
|
boolean |
reportNeighbor(Steerable<T> neighbor)
The callback method used to report a neighbor.
|
Hide<T> |
setArrivalTolerance(float arrivalTolerance)
Sets the tolerance for arriving at the target.
|
Hide<T> |
setDecelerationRadius(float decelerationRadius)
Sets the radius for beginning to slow down.
|
Hide<T> |
setDistanceFromBoundary(float distanceFromBoundary)
Sets the distance from the boundary of the obstacle behind which to hide.
|
Hide<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
Hide<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
Hide<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
Hide<T> |
setProximity(Proximity<T> proximity)
Sets the proximity used to find nearby obstacles.
|
Hide<T> |
setTarget(Location<T> target)
Sets the target to arrive to.
|
Hide<T> |
setTimeToTarget(float timeToTarget)
Sets the time over which to achieve target speed.
|
arrive, getArrivalTolerance, getDecelerationRadius, getTarget, getTimeToTargetcalculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected Proximity<T extends com.badlogic.gdx.math.Vector<T>> proximity
protected float distanceFromBoundary
public Hide(Steerable<T> owner)
Hide behavior for the specified owner.owner - the owner of this behaviorpublic Hide(Steerable<T> owner, Location<T> target)
Hide behavior for the specified owner and target.owner - the owner of this behaviortarget - the target 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 Arrive<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 Proximity<T> getProximity()
public Hide<T> setProximity(Proximity<T> proximity)
proximity - the proximity to setpublic float getDistanceFromBoundary()
public Hide<T> setDistanceFromBoundary(float distanceFromBoundary)
distanceFromBoundary - the distance to setprotected T getHidingPosition(T obstaclePosition, float obstacleRadius, T targetPosition)
distanceFromBoundary away from the object's bounding radius and directly opposite the target. It does this by scaling
the normalized "to obstacle" vector by the required distance away from the center of the obstacle and then adding the result
to the obstacle's position.obstaclePosition - obstacleRadius - targetPosition - public Hide<T> setOwner(Steerable<T> owner)
SteeringBehaviorpublic Hide<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public Hide<T> setLimiter(Limiter limiter)
ArrivesetLimiter in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public Hide<T> setTarget(Location<T> target)
Arrivepublic Hide<T> setArrivalTolerance(float arrivalTolerance)
ArrivesetArrivalTolerance in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>public Hide<T> setDecelerationRadius(float decelerationRadius)
ArrivesetDecelerationRadius in class Arrive<T extends com.badlogic.gdx.math.Vector<T>>