Search code examples
collision-detectiongame-physicsnormalsp-lang

Resolving collision - separating interescting objects causing incident ray to changed


I read some articles that says

As objects intersecting each other isn't physically possible, we have to maintain the realism of the simulation by resolving those collisions by separating them out so that they aren't overlapping.

And to do that, we need to find the separation distance to move it out along the collision normal. enter image description here

But my concern is that once it is separated, it actually move away from the direction of the original incident ray and therefore a new reflected ray. As explained in below graph enter image description here

This means a wrong reflected ray for me. Am I doing it correctly or that's simply something that's expected and we have to live with?


Solution

  • The text is describing the minimum distance to separate the objects, which is independent of the incident ray/object direction. If you were to try to displace the object back along its incident ray, then there are a couple of problems:

    1. By moving the object back along its incident ray, in the next step where the object moves forward along its incident ray, it may end up back in a similar situation where it is overlapping the collision object. This can lead to a loop where the object keeps jumping back and forth along the incident ray.
    2. If the incident ray direction is very close to the surface direction, then the displacement would be relatively large. Generally you want to avoid making large corrections as they may lead to other visible artefacts.

    Regarding your question "This means a wrong reflected ray for me" - technically that's true, but in practice the displacement correction is usually relatively small. As noted above the method in the text is calculating the smallest possible displacement.