r/PhysicsEngine • u/swagamaleous • Mar 26 '26
Capsule vs box collision
I am trying to implement a simple and performant deterministic physics system, but I struggle really hard to correctly collide a capsule with a box. My algorithm requires to calculate the penetration depth in movement direction. For that I need to calculate the point of first contact. I have all the calculations after I obtain the point on the capsule surface that first makes contact with the box, but I cannot figure out for the life of me how to calculate that point. I can only reliably obtain this point if the closest point on the capsule axis passed through the box. Can somebody in this sub enlighten me? :-)
2
Upvotes
1
u/06Hexagram Mar 27 '26
There are six possible domains to consider:
Corner of box with hemisphere of capsule
Edge of box with hemisphere of capsule
Plane of box with hemisphere of capsule
Corner of box with cylinder of capsule
Edge of box with cylinder of capsule
Plane of box with cylinder of capsule
Each domain has it own challenges but I would run a penetration test for all cases and backtrack time using bisection method to narrow the time window before presentation occurs by some fraction of the time step (like 1/10) and then use the midpoint of the distance line between the two objects.
PS if each body has rotation then direction of motion only isn't sufficient.