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\$
5
  • 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
    Commented Dec 25, 2018 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
    Commented Dec 29, 2018 at 19:00
  • \$\begingroup\$ @DMGregory see my edit. Is this what you are looking for? \$\endgroup\$ Commented Dec 30, 2018 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
    Commented Dec 30, 2018 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\$ Commented Dec 30, 2018 at 14:33

1 Answer 1

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .