Example usage for com.badlogic.gdx.ai.steer.behaviors Cohesion Cohesion

List of usage examples for com.badlogic.gdx.ai.steer.behaviors Cohesion Cohesion

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.steer.behaviors Cohesion Cohesion.

Prototype

public Cohesion(Steerable<T> owner, Proximity<T> proximity) 

Source Link

Document

Creates a Cohesion for the specified owner and proximity.

Usage

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

/**
 * Set follow mode/*from   ww w .j a v  a 2s.  c  o m*/
 *
 * @param target the target to follow
 * @return true if it is valid to follow it
 */
public boolean followTarget(CreatureControl target) {
    if (target != null) {
        followTarget = target;
        PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);

        // Create proximity
        Array<CreatureControl> creatures;
        if (party != null) {
            creatures = new Array<>(party.getActualMembers().size());
            for (CreatureControl cr : party.getActualMembers()) {
                creatures.add(cr);
            }
        } else {
            creatures = new Array<>(2);
            creatures.add(target);
            creatures.add(this);
        }

        // Hmm, proximity should be the same instance? Gotten from the party?
        Cohesion<Vector2> cohersion = new Cohesion<>(this, new InfiniteProximity<Vector2>(this, creatures));
        prioritySteering.add(cohersion);

        setSteeringBehavior(prioritySteering);
        return true;
    }
    return false;
}