Hi everyone, is there a simple way to check the collision direction? i mean, if i have two instances of the same gameobject and the 1st obj collide the 2nd one, i need to know whitch of them is ahead then the other one will follow. here a sketch:
http://imageshare.web.id/images/94864rh2dsevggdxsovv.gif
thanks for the patience.
It depends on what the objects are doing. You might be able to check their positions in world space (eg, which one has the highest Z coordinate) to see which one is ahead. If it is a matter of which object can see the other one in front, you can do it with a bit of vector arithmetic.
Subtract object A’s position from object B’s:-
var heading: Vector3 = b.position - a.position;
Then, get the dot product of this heading vector with object A’s transform.forward:-
var dot: float = Vector3.Dot(heading, a.forward);
This value will be greater than zero if object B is ahead and less than zero if it is behind (it will be equal to zero in the unlikely event they are both exactly side by side).
Thanks andeeee, it works like a charm.