0
votes

I'm using AndEngine and Box2d in android application.
What to I have to do so that when player and coin collide, the player goes through coin without hitting against it as if it is a wall?

public class GameScene extends Scene {
  GameScene() {
    Body playerBody = PhysicsFactory.createBoxBody(world, playerSprite, BodyType.DynamicBody, fixtureDef);
    PhysicsConnector playerConnector = new PhysicsConnector(playerSprite, playerBody, true, false);
    world.registerPhysicsConnector(playerConnector);

    Body coinBody = PhysicsFactory.createBoxBody(world, coinSprite, BodyType.StaticBody, fixtureDef);
    PhysicsConnector coinConnector = new PhysicsConnector(coinSprite, coinBody, true, false);
    world.registerPhysicsConnector(coinConnector);
  }

  private ContactListener createContactListener(){
    //if player and coin collide --> destroy coin
  }
}
1

1 Answers

1
votes

Read about sensor fixtures in Box2D. You want your coin to be a sensor. From the Box2D manual:

Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. This is done by using sensors. A sensor is a fixture that detects collision but does not produce a response.