I have two objects which collide. What I want to know when I detect the collision then I want to know from which direction the other collider came from. How can I do this?
One way to find the direction the other collider came from would be:
– Compute the difference between the positions of each object. (i.e. me.position - otherObject.position)
– Normalize this vector. This will give you a unit vector in the direction of the collision. Off the top of my head the above vectors may need to be switched if you get the opposite results. But this will give you a vector for the direction of the collision.
If you just want the direction on just the XZ plane, normalize the difference without the Y component ( Vector3(diff.x,0,diff.z).normalized ).
Hope this helps.
1 Like
I wanted a vector so ty, it was exactly what I needed.