If you keep track of your "wall" or plane as point-normal, it's really easy ([Khan academy link for the math involved][1]). The code would look something like this:
Vector3 wallToObject = wall.position - object.transform.position;
float dot = Vector3.Dot(wallToObject, wall.normal);
if( dot > 0.0f )
// object has passed the wall this frame, move it back and instantiate your collision object
[1]: https://www.khanacademy.org/math/linear-algebra/vectors_and_spaces/dot_cross_products/v/defining-a-plane-in-r3-with-a-point-and-normal-vector
↧