5
votes

I am creating a game using java and box2D (from libgdx).

At this moment I have a problem, when the red body of the image bellow falls, sometimes it does not hit the platform (that is also a dynamic body) because it falls with a high amount of speed and the collision detection is not continuous.

enter image description here

My question is, since both object are dynamic and I want to make sure that the collision between the platform the the red body is detected should I set both bodies to bullet bodies? Only the red body? Or only the platform?

Notes:

  • The red body falls at a very high speed

  • The platform does not move at a high speed

Thank you and merry Christmas!

1
I have never used (J)Box, but quoting from the manual: "In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks." - this sounds exactly like your case to me. So if it works and the performance is OK, is there any reason to not set them both to bullet?Marco13

1 Answers

0
votes

I'd enable bullet-mode for the red body and leave bullet-mode off for the platform body.

At least in the C++ CCD code of Box2D 2.3.2 (see b2World::SolveTOI), all contacts for the given time-step will be reviewed for whether CCD processing needs to be done for them. Essentially contacts having a bullet enabled body or having a non-dynamic body (a static or kinematic body) continue in the CCD process. So the less bullet enabled bodies, the sooner that method can finish.

As such, it's less optimal (algorithmically-speaking) to enable bullet mode on both the red body and the platform body though the difference in performance is unlikely to be noticeable with just the 3 drawn bodies. And given that you're only concerned about collision between the red body and the platform, one being bullet enabled is enough to get their contact to continue on for CCD processing.

As for why I'd bullet enable the red one (as opposed to the platform), that's because, as you state, it'll be moving the fastest of the two and that matches better in my mind with the bullet concept.

Note that if - say in the future - you wind up having more platforms and the platforms themselves need to be unable to tunnel through each other but you were noticing them tunnel (even at their slower speed), then bullet enabling the platforms (instead of the red body) would be the way I'd go.