0
\$\begingroup\$

I'm using bullet to create a 2D topdown game. In my physics proof of concept, I can walk around and push a box. However, if I walk too fast the character goes through the box, instead of colliding with it. See gif:

correctly working at slow speeds player goes inside box

This seems like a common thing to me. However, I cannot find other people having the same problem, so that's why I'm asking a question directly. I'm using a DiscreteDynamicsWorld with two rigid bodies which I step through at 60Hz.

  • Why does this happen?
  • Is there a way to tune bullet to support higher speeds and prevent this issue?

Help is very much appreciated.

Edit

Regarding the question about how I setup collision shapes:

btConvexHullShape shape;
shape.addPoint({-size, size, 0.0f});
shape.addPoint({size, size, 0.0f});
shape.addPoint({size, -size, 0.0f});
shape.addPoint({-size, -size, 0.0f});
\$\endgroup\$
  • 1
    \$\begingroup\$ In ODE, this is tuned with the ERP and CFM parameters. I don't have Bullet setup, so I can only suggest you look for similar parameters in the contact joints. \$\endgroup\$ – Vaillancourt Dec 25 '18 at 19:06
  • \$\begingroup\$ Can you show us how you've set up the collision representation for these shapes? This looks similar to issues I've seen when using polygon/edge-based colliders instead of a box primitive. \$\endgroup\$ – DMGregory Dec 29 '18 at 19:00
  • \$\begingroup\$ @DMGregory see my edit. Is this what you are looking for? \$\endgroup\$ – Aart Stuurman Dec 30 '18 at 13:42
  • \$\begingroup\$ Yes indeed. Have you considered using a btBoxShape for these square objects instead of a btConvexHull? The more primitive colliders are often both faster to process and also simplify the work of calculating & resolving penetration, making it easier for the physics engine to get the desired result. \$\endgroup\$ – DMGregory Dec 30 '18 at 13:47
  • \$\begingroup\$ No have not, but I would like to have more complex shapes later on, so I think it would be good to make it works with a convex hull. However, I will see if there is an improvement by using a box shape. \$\endgroup\$ – Aart Stuurman Dec 30 '18 at 14:33
1
\$\begingroup\$

The issue you are describing is known as 'tunneling.'

By far the easiest way to fix this is to take smaller physics steps.

If you render at 60FPS, don't step through the simulation with 16.7ms. Instead, take two steps of 8.3ms (or even more and smaller steps than that.)

The alternative is to do continuous collision detection. There seem to be some hooks for that in Bullet Physics, but I can't find documentation nor example code for it. In case you want to track it down, start at btDynamicsWorld::btDynamicsWorldType = BT_CONTINUOUS_DYNAMICS_WORLD

My guess is that continuous physics will be a lot more effort to make it work (if it works at all) when compared to the easy fix of smaller timesteps.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.