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

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

Introduction

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

Prototype

public Wander(Steerable<T> owner) 

Source Link

Document

Creates a Wander behavior for the specified owner.

Usage

From source file:com.mygdx.entities.DynamicEntities.enemies.Enemy_TestMon.java

public Enemy_TestMon(Vector2 pos) {
    super(pos, 40f, 40f);

    idleTexture = MainGame.am.get(ResourceManager.ENEMY_PH);
    deadTexture = MainGame.am.get(ResourceManager.ENEMY_PH_DEAD);

    texture = idleTexture;// www  .j  a v  a  2s. com

    //AI
    wanderSB = new Wander<Vector2>(this).setFaceEnabled(false).setAlignTolerance(0.001f)
            .setDecelerationRadius(5).setTimeToTarget(0.1f).setWanderOffset(90).setWanderOrientation(10)
            .setWanderRadius(40f).setWanderRate(MathUtils.PI2 * 4);

    seekWanderSB = new Seek<Vector2>(this, seekWanderTarget);
    fleeSB = new Flee<Vector2>(this, EnvironmentManager.player);

    this.maxLinearSpeed = 150f;
    this.maxLinearAcceleration = 500f;
    this.maxAngularSpeed = 30f;
    this.maxAngularAcceleration = 5f;
}

From source file:com.mygdx.entities.DynamicEntities.enemies.En_Goober.java

public En_Goober(Vector2 pos) {
    super(pos, 30f * RATIO, 30f * RATIO);
    fd.restitution = 0.2f;/*from  w  w w  .j  a v  a 2s  .  com*/

    float sscale = 0.38f * RATIO;

    moveSprite = new ImageSprite("goober_move", true);
    moveSprite.sprite.setScale(sscale);
    isprite = moveSprite;

    prepSprite = new ImageSprite("goober_prep", true);
    prepSprite.sprite.setScale(sscale);

    attackSprite = new ImageSprite("goober-attack2", false);
    attackSprite.sprite.setScale(sscale);

    bodyDamageSprite = new ImageSprite("goober-dmg", false);
    bodyDamageSprite.sprite.setScale(sscale);

    prepTime = 1.0f;
    attTime = 0.3f;
    recovTime = 3f;

    attackFC = new FrameCounter_Attack(prepTime, attTime, recovTime);

    //attack sensors
    attFd1 = new FixtureDef();
    PolygonShape vertBox = new PolygonShape();
    vertBox.setAsBox(width * 0.4f / PPM, (75f / PPM) * RATIO, new Vector2(0, (75f / PPM) * RATIO), 0);
    attFd1.shape = vertBox;
    attFd1.isSensor = true;
    attFd1.filter.categoryBits = BIT_EN;
    attFd1.filter.maskBits = BIT_PLAYER;

    attFd2 = new FixtureDef();
    PolygonShape horzBox = new PolygonShape();
    horzBox.setAsBox((75f / PPM) * RATIO, width * 0.4f / PPM, new Vector2((75f / PPM) * RATIO, 0), 0);
    attFd2.shape = horzBox;
    attFd2.isSensor = true;
    attFd2.filter.categoryBits = BIT_EN;
    attFd2.filter.maskBits = BIT_PLAYER;

    attFd3 = new FixtureDef();
    PolygonShape vertBoxSouth = new PolygonShape();
    vertBoxSouth.setAsBox(width * 0.4f / PPM, (75f / PPM) * RATIO, new Vector2(0, -(75f / PPM) * RATIO), 0);
    attFd3.shape = vertBoxSouth;
    attFd3.isSensor = true;
    attFd3.filter.categoryBits = BIT_EN;
    attFd3.filter.maskBits = BIT_PLAYER;

    attFd4 = new FixtureDef();
    PolygonShape horzBoxWest = new PolygonShape();
    horzBoxWest.setAsBox((75f / PPM) * RATIO, width * 0.4f / PPM, new Vector2(-(75f / PPM) * RATIO, 0), 0);
    attFd4.shape = horzBoxWest;
    attFd4.isSensor = true;
    attFd4.filter.categoryBits = BIT_EN;
    attFd4.filter.maskBits = BIT_PLAYER;

    //ai
    moveToSB = new Arrive<Vector2>(this, EnvironmentManager.player).setTimeToTarget(0.01f)
            .setArrivalTolerance(2f).setDecelerationRadius(10);

    wanderSB = new Wander<Vector2>(this).setFaceEnabled(false).setAlignTolerance(0.001f)
            .setDecelerationRadius(5).setTimeToTarget(0.1f).setWanderOffset(90).setWanderOrientation(10)
            .setWanderRadius(40f).setWanderRate(MathUtils.PI2 * 4);

    seekWanderSB = new Seek<Vector2>(this, seekWanderTarget);

    //ai
    this.maxLinearSpeed = 150f;
    this.maxLinearAcceleration = 500f;
    this.maxAngularSpeed = 30f;
    this.maxAngularAcceleration = 5f;

}

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

License:Apache License

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

    this.wanderSB = new Wander<Vector3>(steerableBody) {
        @Override//from w  w w.j  av a2 s .c o  m
        protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) {
            super.calculateRealSteering(steering);
            steering.linear.y = 0; // remove any vertical acceleration
            return steering;
        }
    };
    this.wanderSB.setWanderOffset(8) //
            .setWanderOrientation(0) //
            .setWanderRadius(0.5f) //
            .setWanderRate(MathUtils.PI2 * 4);

    this.prioritySteering.add(wanderSB);
}

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);/* www. ja  v  a 2s. 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);
}