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; }