2
votes

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!

1
You most likely screwed up your bit filters. Post all relevant code. The problem is 100% not with the setTransform() method so that snippet is useless (not to mention confusing for those that may be having similar problems).David Titarenco
Here are my bit filters: For the obstacle: fdef.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 FixtureDefFélix Poitras

1 Answers

4
votes

from the manual here:

http://www.box2d.org/manual.html#_Toc258082973

Kinematic bodies do not collide with other static or kinematic bodies.

you'll have to figure out a new way to trigger the despawner. you won't be able to get collision between two kinetic or a kinetic and a static body type. maybe a body with a sensor fixture. or a Y position value. or a dynamic body with gravity turned off.

game looks cool, looking forward to it.