When the external rigid body moves, the collision objects inside the rigid body leak out

Post Reply
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

When the external rigid body moves, the collision objects inside the rigid body leak out

Post by water »

I set up a cuboid, and set up a small ball in the inside of the cuboid to fall under the influence of gravity and spring up elastically. I set the Euler angle of the cuboid rotation, but I found that when the Euler angle changes a little, the ball can move normally, but when I increase the degree, the ball can't move with the cuboid but leaks out. How can I solve this problem?

thank you very much indeed
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the external rigid body moves, the collision objects inside the rigid body leak out

Post by drleviathan »

When you change the rotation of the hollow box you are effectively "teleporting" it to a new transform. If its new transform happens to put its walls into penetration with balls that used to be inside --> then Bullet's "penetration resolution" algorithm will kick in and it doesn't care about keeping the balls on the inside of the box. It just tries to resolve the penetrations as fast as possible and might try to resolve it by pushing balls to the outside.

When "teleporting" the container there is no 100% reliable general way to prevent the balls from tunneling through it using Bullet config. You can make it less likely to happen by doing things like:

(1) Use smaller substeps
(2) Make the walls of the box thicker
(3) Make the box kinematic and always set its velocities (angular and linear) to effectively "agree" with any teleports you're doing
(4) Enable continuous collision detection (CCD) for the balls which will help the case when the balls themselves are moving fast

If you're lucky, and limit how much you rotate the container per-substep then those tricks might solve all tunneling issues for your particular simulation.

Note: if the balls should never ever be outside the box then a suitably aggressive version of (2) could solve all your problems. Make the walls of the box really really thick convex shapes, but render them as appropriately "thin" walls that line up with the inner surface.
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: When the external rigid body moves, the collision objects inside the rigid body leak out

Post by water »

I really appreciate your help. but how can I increase the thickness of the rigid body?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the external rigid body moves, the collision objects inside the rigid body leak out

Post by drleviathan »

The simplest way would be to use a btConvexHullShape for each cuboid wall and assemble them into a btCompoundShape. The points for each convex hull would be the eight corners of the wall box, and you could let all the points be in the local-frame of the btCompoundShape, so you could supply identity transform for each subshape's parent-relative transform. You can make the walls as thick as you like by picking the right points. Note it is ok, and probably better, if the walls overlap at the corners --> the stuff on the inside will be less likely to escape.
Post Reply