I am going to reuse Unity Physics’s Collision detection for my own custom physics system, and I am slightly worried about the use of speculative contacts for my use case. They are cool and seem to be designed to help solve tunneling, however, I am concerned about ghost collisions. Would it be a bad idea to try to disable speculative contacts? In my use case, the convex hulls seem large enough that tunneling should be uncommon.
Thank you for the insight, it is incredibly helpful.
Without speculative contacts, bodies can penetrate or tunnel. For example, think about dropping a ball on the floor. With speculative contacts it should land precisely on the floor. Without them, it will have to penetrate the floor before the collision is detected, then it will be pushed back out of the floor over time. If the ball is falling fast enough, it might even just go through the floor completely without ever touching it. Those problems can be reduced by taking shorter steps, although that also reduces ghost collisions from speculative contacts.
Another consideration is that penetration increases the cost of collision detection. When shapes are separated we only need GJK to find the closest points, but when they penetrate we need EPA, which is a lot slower.
If you want to try disabling speculative contacts, I think it would work to have MotionVelocity.CalculateExpansion() return MotionExpansion.Zero.
Thanks for writing this. This is helpful. My use case is an object sliding on a static floor. So my current hypothesis is ghost collisions are too dangerous for my use case. Thank you.
Hello, I want to know if this is related to a problem I’m facing.
When I shoot bullets downwards to the ground instead of them to ricochet against the ground, they just get fired upwards to the sky.
Hi tavovallejo, hard to say. Can you make a video that shows the problem? Normally when a body hits a flat surface, unless its restitution is greater than zero it should just slide along that surface.
Totally agree on casting for fast bullets. If you do want to understand what is going on with your rigidbody bullet I’d suggest adding a Debug Display component and enabling the Collider, Broadphase and Contacts viewers
Then when you step the simulation one frame at the time you’ll see where the collision as being detected and applied.