Clarification regarding penetration and narrow-phase callbacks #297
-
Hello! To render objects in my game engine, a 3D model follows its associated physics body. I noticed that certain objects (say, a box falling to the ground) visually clip into the ground for a single frame, with the magnitude of the clip dependent on velocity. The image below demonstrates the problem. The left column ("Expected") matches my understanding of how Bepu's narrow phase works. On frame 0, the box is still airborne and falling downward (fast enough that it'll hit the ground next frame). On frame 1, the box penetrates the ground (with whatever depth), then Bepu resolves that collision by pushing the box back up and out. Assuming no bounciness, I'd expect the box's resulting position (i.e. its position after the simulation step completes) to be resting comfortably on the ground. In other words, there's never a frame where the box remains overlapping the ground. The right column ("Actual") demonstrates what's actually occurring. Frame 0 is the same as above (the box is airborne and falling fast enough to hit the ground next frame). On frame 1, the box partially penetrates the ground, i.e. it's still clipped into the ground after the simulation's step completes, without calling into narrow-phase callbacks. On frame 2, Bepu resolves the collision by pushing the box up and out. To reiterate, narrow-phase callbacks for the box are not called until frame 2. Given this reality, it's clear why 3D models visually clip beneath the ground for a single frame (they're correctly following their associated physics body, which itself clips into the ground for a single frame). I've tested with both kinematic and dynamic objects. I'd like to clarify whether my understanding on Bepu's collision resolution is accurate. If so, then so be it. If not, then it's likely I've made another mistake and can continue investigating. Note that this question is not about continuous collision detection. The box is plenty large enough and moving slowly enough that it doesn't come close to tunneling through the ground's plane. I even turned on CCD as a sanity check and the results illustrated above didn't change. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In isolation, the behavior of the body in the image makes sense; all contacts are configurable springs. Softer springs will allow more overlap upon collision. But if the body's velocity was modified during a frame by a collision, then contacts must have been created, and if that's the case, then narrow phase callbacks should have fired. Contacts can have negative depth during the callback (so-called speculative contacts) and still change velocity if the incoming velocity is high enough that the contact would be activated at some point over the next timestep.
|
Beta Was this translation helpful? Give feedback.
By the way, with 2.4 and up, you can almost always just leave speculative margins at float.MaxValue (which is the default when no margin is provided). The effective margin scales with velocity automatically.