Java 类com.badlogic.gdx.ai.steer.proximities.RadiusProximity 实例源码

项目:GdxDemo3D    文件:CollisionAvoidanceSteererBase.java   
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
        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);
}
项目:GDXJam    文件:EntityFactory.java   
public static Entity createSquad (Vector2 position, Faction faction) {
    Entity entity = builder.createEntity(EntityCategory.SQUAD, position).physicsBody(BodyType.DynamicBody).circleSensor(30.0f)
        .faction(faction).target().filter(EntityCategory.SQUAD, 0, EntityCategory.SQUAD | EntityCategory.RESOURCE)
        .steeringBehavior().stateMachine().getWithoutAdding();

    SteerableComponent steerable = engine.createComponent(SteerableComponent.class).init(
        Components.PHYSICS.get(entity).getBody(), 30.0f);
    SquadComponent squadComp = engine.createComponent(SquadComponent.class).init(steerable);
    squadComp.targetLocation.getPosition().set(position);
    entity.add(squadComp);

    // A good rule of thumb is to make the maximum speed of the formation
    // around
    // half that of the members. We also give the anchor point far less
    // acceleration.
    steerable.setMaxLinearSpeed(SteerableComponent.MAX_LINEAR_SPEED / 2);
    steerable.setMaxLinearAcceleration(SteerableComponent.MAX_LINEAR_ACCELERATION / 10);

    Arrive<Vector2> arriveSB = new Arrive<Vector2>(steerable).setTarget(squadComp.targetLocation).setTimeToTarget(0.001f)
        .setDecelerationRadius(2f).setArrivalTolerance(0.0001f);
    SteeringBehavior<Vector2> sb = arriveSB;

    RadiusProximity<Vector2> proximity = new RadiusProximity<Vector2>(steerable, squadComp.friendlyAgents, 3.0f);
    Separation<Vector2> separationSB = new Separation<Vector2>(steerable, proximity);

    BlendedSteering<Vector2> blendedSteering = new BlendedSteering<Vector2>(steerable) //
        .setLimiter(NullLimiter.NEUTRAL_LIMITER) //
        .add(separationSB, 10000f)
        .add(arriveSB, 0.5f);
    sb = blendedSteering;
    Components.FSM.get(entity).changeState(SquadComponent.DEFAULT_STATE);

    Components.STEERING_BEHAVIOR.get(entity).setBehavior(sb);

    entity.add(steerable);

    engine.addEntity(entity);
    return entity;
}