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
}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.