T - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class Cohesion<T extends com.badlogic.gdx.math.Vector<T>> extends GroupBehavior<T> implements Proximity.ProximityCallback<T>
Cohesion is a group behavior producing a linear acceleration that attempts to move the agent towards the center of mass
of the agents in its immediate area defined by the given Proximity. The acceleration is calculated by first iterating
through all the neighbors and averaging their position vectors. This gives us the center of mass of the neighbors, the place
the agents wants to get to, so it seeks to that position.
A sheep running after its flock is demonstrating cohesive behavior. Use this behavior to keep a group of agents together.
proximityenabled, limiter, owner| Constructor and Description |
|---|
Cohesion(Steerable<T> owner,
Proximity<T> proximity)
Creates a
Cohesion 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.
|
Cohesion<T> |
setEnabled(boolean enabled)
Sets this steering behavior on/off.
|
Cohesion<T> |
setLimiter(Limiter limiter)
Sets the limiter of this steering behavior.
|
Cohesion<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 Cohesion<T> setOwner(Steerable<T> owner)
SteeringBehaviorsetOwner in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public Cohesion<T> setEnabled(boolean enabled)
SteeringBehaviorsetEnabled in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>public Cohesion<T> setLimiter(Limiter limiter)
setLimiter in class SteeringBehavior<T extends com.badlogic.gdx.math.Vector<T>>