2
\$\begingroup\$

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:

  1. Execute a swept-object/world collision check
  2. Move the object up to the exact point where it collides
  3. If no time is remaining, everything is done, just stop
  4. 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.

\$\endgroup\$
5
  • \$\begingroup\$ Your question is slightly confusing, can you clarify, are the black and red arrows all happening in one single step, or is each one happening in a different frame, and so you're seeing jitter/zig-zag from side to side while it proceeds over time? \$\endgroup\$ – Joshua Hedges Apr 24 '20 at 0:47
  • \$\begingroup\$ I modified the color for each frame, I hope it's clearer what's going on now. \$\endgroup\$ – Marc Perlade Apr 24 '20 at 11:28
  • \$\begingroup\$ Watching this question now for a while, I'll try to help you out if you are still looking for a solution. However, I have a question: Which is the "good path" you are looking for? Along the corner of the surfaces A and B? \$\endgroup\$ – wychmaster Apr 26 '20 at 11:24
  • \$\begingroup\$ Yes, along the intersection line of both planes A and B. \$\endgroup\$ – Marc Perlade Apr 26 '20 at 11:53
  • \$\begingroup\$ I think the main problem is, that you need to treat an already corrected vector differently than an unmodified one. After the first collision of the vector, you need to pass this information to every subsequent collision check. During the handling of the second collision, you have to check if the vector is still in contact with the first object it collided with. If so, the new vector must be calculated with a different approach. However, this depends on the type of contact. A convex corner will be treated different than a concave one. \$\endgroup\$ – wychmaster Apr 26 '20 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.