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

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

Introduction

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

Prototype

public PrioritySteering(Steerable<T> owner, float epsilon) 

Source Link

Document

Creates a PrioritySteering behavior for the specified owner and threshold.

Usage

From source file:com.mygdx.game.steerers.CollisionAvoidanceSteererBase.java

License:Apache License

public CollisionAvoidanceSteererBase(final SteerableBody steerableBody) {
    super(steerableBody);

    this.proximity = new RadiusProximity<Vector3>(steerableBody, GameScreen.screen.engine.characters,
            steerableBody.getBoundingRadius() * 1.8f);
    this.collisionAvoidanceSB = new CollisionAvoidance<Vector3>(steerableBody, proximity) {
        @Override//from  w  w  w . j a  v  a2s . c  om
        protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) {
            super.calculateRealSteering(steering);
            steering.linear.y = 0; // remove any vertical acceleration
            return steering;
        }
    };

    this.prioritySteering = new PrioritySteering<Vector3>(steerableBody, 0.001f) //
            .add(collisionAvoidanceSB);
}

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

License:Open Source License

public void wander() {

    // Set wandering
    PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
    RaycastCollisionDetector<Vector2> raycastCollisionDetector = new CreatureRayCastCollisionDetector(
            worldState);//  ww w  .j  a v  a  2  s.  co m
    RaycastObstacleAvoidance<Vector2> raycastObstacleAvoidanceSB = new RaycastObstacleAvoidance<>(this,
            new SingleRayConfiguration<>(this, 1.5f), raycastCollisionDetector, 0.5f);
    prioritySteering.add(raycastObstacleAvoidanceSB);
    prioritySteering.add(new Wander<>(this).setFaceEnabled(false) // We want to use Face internally (independent facing is on)
            .setAlignTolerance(0.001f) // Used by Face
            .setDecelerationRadius(5) // Used by Face
            .setTimeToTarget(0.1f) // Used by Face
            .setWanderOffset(10) //
            .setWanderOrientation(10) //
            .setWanderRadius(10) //
            .setWanderRate(FastMath.TWO_PI * 4));
    setSteeringBehavior(prioritySteering);
}

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

License:Open Source License

public void navigateToRandomPoint() {
    Point p = worldState.findRandomAccessibleTile(
            worldState.getTileCoordinates(getSpatial().getWorldTranslation()), 10, creature);
    if (p != null) {
        GraphPath<TileData> outPath = worldState
                .findPath(worldState.getTileCoordinates(getSpatial().getWorldTranslation()), p, creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }/*from   w w  w  .  j  a v  a  2 s. c  om*/
    }
}

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

License:Open Source License

public void navigateToAssignedTask() {

    Vector2f loc = assignedTask.getTarget(this);
    if (loc != null) {
        GraphPath<TileData> outPath = worldState.findPath(
                worldState.getTileCoordinates(getSpatial().getWorldTranslation()),
                new Point((int) Math.floor(loc.x), (int) Math.floor(loc.y)), creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }/*from  w w w .j  a  v a 2  s .  c o  m*/
    }
}

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

License:Open Source License

/**
 * Set follow mode/* w  w  w. j  a va 2  s.c  om*/
 *
 * @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;
}