T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class Wander<T extends com.badlogic.gdx.math.Vector<T>> extends Face<T>
Wander behavior is designed to produce a steering acceleration that will give the impression of a random walk through
the agent's environment. You'll often find it a useful ingredient when creating an agent's behavior.
There is a circle in front of the owner (where front is determined by its current facing direction) on which the target is constrained. Each time the behavior is run, we move the target around the circle a little, by a random amount. Now there are 2 ways to implement wander behavior:
Seek behavior, and performs a LookWhereYouAreGoing behavior to
correct its orientation.Face behavior to align to the target, and applies full
linear acceleration in the direction of its current orientation.
This implementation uses the second approach. However, if you manually align owner's orientation to its linear velocity on each
time step, Face behavior should not be used (which is the default case). On the other hand, if the owner has
independent facing you should explicitly call setFaceEnabled(true) before using Wander
behavior.
Note that this behavior internally calls the GdxAI.getTimepiece().getTime() method to get the
current AI time and make the wanderRate FPS independent. This means that
update the timepiece the wander orientation won't change.This steering behavior can be used to produce a whole range of random motion, from very smooth undulating turns to wild Strictly Ballroom type whirls and pirouettes depending on the size of the circle, its distance from the agent, and the amount of random displacement each frame.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
faceEnabled
The flag indicating whether to use
Face behavior or not. |
protected float |
lastTime
The last time the orientation of the wander target has been updated
|
protected float |
wanderOffset
The forward offset of the wander circle
|
protected float |
wanderOrientation
The current orientation of the wander target
|
protected float |
wanderRadius
The radius of the wander circle
|
protected float |
wanderRate
The rate, expressed in radian per second, at which the wander orientation can change
|
alignTolerance, decelerationRadius, target, timeToTargetenabled, limiter, owner| Constructor and Description |
|---|
Wander(Steerable<T> owner)
Creates a
Wander behavior for the specified owner. |
| 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.
|
T |
getInternalTargetPosition()
Returns the current position of the wander target.
|
T |
getWanderCenter()
Returns the current center of the wander circle.
|
float |
getWanderOffset()
Returns the forward offset of the wander circle.
|
float |
getWanderOrientation()
Returns the current orientation of the wander target.
|
float |
getWanderRadius()
Returns the radius of the wander circle.
|
float |
getWanderRate()
Returns the rate, expressed in radian per second, at which the wander orientation can change.
|
boolean |
isFaceEnabled()
Returns the flag indicating whether to use
Face behavior or not. |
Wander<T> |
setAlignTolerance(float alignTolerance)
Sets the tolerance for aligning to the target without letting small errors keep the owner swinging.
|
Wander<T> |
setDecelerationRadius(float decelerationRadius)
Sets the radius for beginning to slow down
|
Wander<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
Wander<T> |
setFaceEnabled(boolean faceEnabled)
Sets the flag indicating whether to use
Face behavior or not. |
Wander<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
Wander<T> |
setOwner(Steerable<T> owner)
Sets the owner of this steering behavior.
|
Wander<T> |
setTarget(Location<T> target)
Sets the target to align to.
|
Wander<T> |
setTimeToTarget(float timeToTarget)
Sets the time over which to achieve target rotation speed
|
Wander<T> |
setWanderOffset(float wanderOffset)
Sets the forward offset of the wander circle.
|
Wander<T> |
setWanderOrientation(float wanderOrientation)
Sets the current orientation of the wander target.
|
Wander<T> |
setWanderRadius(float wanderRadius)
Sets the radius of the wander circle.
|
Wander<T> |
setWanderRate(float wanderRate)
Sets the rate, expressed in radian per second, at which the wander orientation can change.
|
getAlignTolerance, getDecelerationRadius, getTarget, getTimeToTarget, reachOrientationcalculateSteering, getActualLimiter, getLimiter, getOwner, isEnabled, newVectorprotected float wanderOffset
protected float wanderRadius
protected float wanderRate
protected float lastTime
protected float wanderOrientation
protected boolean faceEnabled
Face behavior or not. This should be set to true when independent facing
is used.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 Face<T extends com.badlogic.gdx.math.Vector<T>>steering - the steering acceleration to be calculated.public float getWanderOffset()
public Wander<T> setWanderOffset(float wanderOffset)
public float getWanderRadius()
public Wander<T> setWanderRadius(float wanderRadius)
public float getWanderRate()
public Wander<T> setWanderRate(float wanderRate)
public float getWanderOrientation()
public Wander<T> setWanderOrientation(float wanderOrientation)
public boolean isFaceEnabled()
Face behavior or not.public Wander<T> setFaceEnabled(boolean faceEnabled)
Face behavior or not. This should be set to true when independent
facing is used.public T getInternalTargetPosition()
public T getWanderCenter()
public Wander<T> setOwner(Steerable<T> owner)
SteeringBehaviorpublic Wander<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class Face<T extends com.badlogic.gdx.math.Vector<T>>public Wander<T> setLimiter(Limiter limiter)
faceEnabled is true, it must take care of the maximum angular speed and acceleration.setLimiter in class Face<T extends com.badlogic.gdx.math.Vector<T>>public Wander<T> setTarget(Location<T> target)
ReachOrientation, but is completely useless
for Wander because owner's orientation is determined by the internal target, which is moving on the wander circle.public Wander<T> setAlignTolerance(float alignTolerance)
ReachOrientationsetAlignTolerance in class Face<T extends com.badlogic.gdx.math.Vector<T>>public Wander<T> setDecelerationRadius(float decelerationRadius)
ReachOrientationsetDecelerationRadius in class Face<T extends com.badlogic.gdx.math.Vector<T>>public Wander<T> setTimeToTarget(float timeToTarget)
ReachOrientationsetTimeToTarget in class Face<T extends com.badlogic.gdx.math.Vector<T>>