I'm working on a game using the Box2D extension of the LibGdx library and everything is working like it should except for the collision detection.
This is what it currently looks like: Image
The idea is the player (little circle) can jump in his bounds (gravity is set towards the center of the ground) to dodge the incoming obstacles, which are rotating around the ground. Once the obstacles reach the despawner, the ContactListener should call a method that will destroy the obstacle body.
First of all, I have a few different bodies:
- Player (Dynamic Body)
The player is only affected by the gravity and some applied forces (no transforms) - Ground (Kinematic Body)
The ground only has a linearVelocity (that's why it's not a static body) - Obstacle (Kinematic Body)
The obstacle is moved using the setTransform(position, angle) method - Despawner (Static Body)
I'm also using bit filters to manage the collisions (which I've triple checked and are not the source of the problem).
The actual problem is that my ContactListener doesn't call the beginContact() method when the Obstacle Body is part of the collision, except if he's colliding with the Player Body. All the other bodies collide just fine with each other.
Thank you for your help!
setTransform()
method so that snippet is useless (not to mention confusing for those that may be having similar problems). – David Titarencofdef.filter.categoryBits = BIT_OBSTACLE; fdef.filter.maskBits = BIT_DESPAWNER | BIT_PLAYER;
For the despawner:fdef.filter.categoryBits = BIT_DESPAWNER; fdef.filter.maskBits = BIT_OBSTACLE;
For the player:fdef.filter.categoryBits = BIT_PLAYER; fdef.filter.maskBits = BIT_GROUND | BIT_OBSTACLE;
fdef being the FixtureDef – Félix Poitras