I am programming a 3D game physics engine that uses continuous collision detection to avoid my objects from being able to "tunnel" through the geometry.
Here is basically how it works:
- Execute a swept-object/world collision check
- Move the object up to the exact point where it collides
- If no time is remaining, everything is done, just stop
- Else, update the velocity so that the object "slides" in a direction orthogonal to the collision normal before returning to step 1. This is the formula I use for this sliding (I just remove the component of the motion in the normal direction):
velocity = velocity - (velocity dot normal) * normal
My problem occurs in this kind of situation:
(Do not take into account faces other than A and B, their only purpose is the emphasize the 3D aspect of the shape)
In the first frame, the object first follows the black arrow, then collides face A. It slides correctly on face A (first red arrow) and then climbs on face B (second red arrow). The problem with this algorithm is precisely the fact that it can climb on the opposite face: after several consecutive frames (here the other frames are the cyan and green ones), the general motion will follow the good path (the intersection line of planes A and B), but with a local left-right shaking artifact that I would appreciate getting rid of.
Any idea to solve this would be greatly appreciated.