简体   繁体   中英

Box2D not detecting collision

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!

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM