As unity3d developers no if an objects velocity is high enough it can pass through an object creating a collision on the wrong side.
I believe a fix for this is to have a ray detect if the collider passed through an object at its new location. With the ray a calculation can be done to make the physics engine send the particle into the correct direction, rather then it passing through to the other side on other colliders.
The physics engine has modes to facilitate the fast moving issue:
Note the various modes have side effects.
For example, lets just consider your method of solving. A raycast…
-
A ray is only a line, where as your object has depth and width. What if the collision point is not in line with a ray out the middle of your collider? Do you have to cast multiple rays? Sphere cast? What?
-
What if the thing in front of you is ALSO in motion. A raycast now and the object isn’t there, but when your object actually gets there, it is there. Like 2 cars driving through an intersection. If all you see is the frame before they enter, and the frame upon their leaving… you don’t know that a collision would have occurred, no matter the number of raycasts you perform, because it only occurs when both are there at the same time… in between frames.
What the modes above do is that it allows for actually sampling collision along the path over the time of the simulation. The slowest of them ‘ContinuousDynamic’ sampling not just the bodies motion, but the motion of other bodies around it.
It’s not so much a raycast, but instead a quickly updating along multiple steps between frames. So if say physics calculates at 50 times per second, this inserts calculations in between those steps so that the effective calculation for a given body might be 200 times per second, but only for that body.