I have a game, where with the gyroscope, i control a couple of blocks. Now the problem is that i have inplemented box2d in my andengine code, but the bodies do not seem to react one at another, causing them to overlap, instead of actually doing the physics stuff.
In my onCreateScene i have this:
@Override
protected Scene onCreateScene() {
this.mMainScene = new Scene();
backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
physicsWorld = new PhysicsWorld(new Vector2(0, 0), false);
final Player oPlayer = new Player(centerX, centerY, this.goodTiledTextureRegion, this.getVertexBufferObjectManager(), MainActivity.this, playerID, 0);
player_fix = PhysicsFactory.createFixtureDef(10.0f, 0.2f, 1.0f);
body = PhysicsFactory.createBoxBody(physicsWorld, oPlayer, BodyType.DynamicBody, player_fix);
oPlayer.setBody(body);
playerID++;
players.add(oPlayer);
for (Player player : players) {
player.setPlayers(players);
mMainScene.attachChild(player);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(player, body, true, false));
mMainScene.registerTouchArea(player);
}
this.mMainScene.registerUpdateHandler(physicsWorld);
this.mMainScene.registerUpdateHandler(new TimerHandler(0.1f, true, new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
Player player = new Player(random, 5, goodTiledTextureRegion, getVertexBufferObjectManager(), MainActivity.this, playerID, 0);
body = PhysicsFactory.createBoxBody(physicsWorld, player, BodyType.DynamicBody, player_fix);
player.setBody(body);
players.add(player);
mMainScene.detachChildren();
mMainScene.attachChild(backgroundSprite);
for (Player player : players) {
player.setPlayers(players);
mMainScene.attachChild(player);
player.body.setLinearVelocity(AccelerometerHelper.TILTX * 5, AccelerometerHelper.TILTY * 5);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(player, body, true, false));
mMainScene.registerTouchArea(player);
}
}
return this.mMainScene;
}
Now, I create the scene, I create the physics world. Then i create my first "player", (this is a sprite, that i move). I create a body for it, and also set that body in my Player.class (entity). to have access to every players body, from it's entity. Then on every a couple of updates (the code is a bit longer, but i took out the stuff that doesn't have anything to do with physics) I create a new player. and then for every player in my arraylist (players), i set the linear velocity after the accelerometer, to make it move. The problem is that if a player hits another one, they overlap, and do not react at the impact.
the player fixture is the same everywhere player_fix = PhysicsFactory.createFixtureDef(10.0f, 0.2f, 1.0f);
And the BodyType is always DynamicBody. Can somebody tell me what I am missing?