Created
October 18, 2014 19:04
-
-
Save najmam/57465c6423f5965f6416 to your computer and use it in GitHub Desktop.
Integrating gdx-ai's steering behaviours with Ashley and Box2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// apply steering behaviors | |
ImmutableArray<Entity> entities = engine.getEntitiesFor(Family.getFor(SteerAgentComponent.class)); | |
for(int i = 0; i < entities.size(); i++) { | |
Entity e = entities.get(i); | |
Body body = e.getComponent(PhysicalBodyComponent.class).body; | |
SteerAgentComponent steer = e.getComponent(SteerAgentComponent.class); | |
if(steer.steeringBehavior == null) { | |
continue; | |
} | |
steer.steeringBehavior.calculateSteering(steer.steeringOutput); | |
Vector2 linear_force = steer.steeringOutput.linear.cpy(); | |
linear_force.scl(body.getMass()); | |
body.applyForceToCenter(linear_force, true); | |
body.applyTorque(steer.steeringOutput.angular*body.getInertia(), true); | |
} | |
// step the simulation | |
world.step(Constants.PHYSICS_TIME_STEP, Constants.PHYSICS_VELOCITY_ITERATIONS, Constants.PHYSICS_POSITION_ITERATIONS); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment