After following the Objective-C tutorial (and converting to C++), this happened

Post Reply
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: After following the Objective-C tutorial (and converting to C++), this happened

Post by drleviathan »

I watched the video. What I saw: a dynamic box descended and bounce on the floor (which appeared to be thin mesh square). Upon hitting the floor a second time the box tunnelled through and continued falling.

Tunnelling... it is a known problem with physics simulations. There are a few ways to solve it for your case:

(1) Use a convex shape for the floor rather than a thin mesh. Make sure the vertical dimension of your convex shape is larger than 2X the max expected per-substep position change of your dynamic box.

(2) Enable continuous collision detection (CCD), and configure it properly, for the dynamic box.

(3) If you really must use a thin shape for the floor... take smaller substeps such that the box never moves more than 1/2 its smallest dimension at whatever it its maximum expected velocity.
Starconstructor
Posts: 3
Joined: Mon Feb 10, 2020 5:56 pm

Re: After following the Objective-C tutorial (and converting to C++), this happened

Post by Starconstructor »

Great. What’s the terminology for other potential problems with physics, so I don’t have to come back?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: After following the Objective-C tutorial (and converting to C++), this happened

Post by drleviathan »

Alas, that question is too broad. The answer spans entire textbooks on the subject. Best to come back when you have a specific issue or question.
Starconstructor
Posts: 3
Joined: Mon Feb 10, 2020 5:56 pm

Re: After following the Objective-C tutorial (and converting to C++), this happened

Post by Starconstructor »

So I tried fixing, including enabling and configuring ccd (with extremely low threshold just for debugging), growing the floor to be 10 meters deep, and decreasing the substep, none of which prevented the box from tunneling. I'm at my wit's end.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: After following the Objective-C tutorial (and converting to C++), this happened

Post by drleviathan »

Something funny is going on: I would not expect what you claim to see.

I reviewed the video more carefully so I could read your code. You appear to be using btConvexHullShape for everything which should be safe. The falling box is dynamic and the floor is static (mass = 0) ok.

I assume you're not doing anything funny in Box::update() that would override the Body's position in the physics simulation.

You're using the default behavior of btDiscreteDynamicsWorld::stepSimulation(dt) which clamps the substep to 1/60 of a second and takes only one substep per call, which is safe.

Restitution and friction are fine. Inertia tensor is computed by the shape and should be reasonable.

I dunno what is happening. My advice would be:

Try taking shorter timesteps just to see if it solves it. This is an easy change so worth trying before trying more laborious sanity checking.

Plot the position over time to see at which step it goes bad. Step through the simulation one step at a time and perform sanity checking to try to narrow down where exactly the simulation goes wrong. That is, can you catch it in the act when the dynamic box really is overlapping with the floor, and in that case, what are the details of the contact manifold?

Supply the full codebase so others can verify and examine the code.
Post Reply