Well my case is that I’m going through waypoints, and I’m calculating distance from waypoint to GameObject.
But the flaw is that the distance is in absolute value, so i’d like to make the sign negative when the waypoint is behind me, I suspect it has something to do with the angle of my GameObject?
The reason I want to do this is, i want to find out the traveled distance along spline of my GameObject.
Any help would be apriciated, Thanks!
// detects if other transform is behind this object
var other : Transform;
function Update() {
if (other) {
var forward = transform.TransformDirection(Vector3.forward);
var toOther = other.position - transform.position;
if (Vector3.Dot(forward,toOther) < 0)
print ("The other transform is behind me!");
}
}
Didnt think of using Dot, but yeah overall my idea seems to be bad anyway :/, because this way I have t ocalculate the distance back. Just tryed some quick implementations and the waypoints went nuts lol. I’ll see what Atan2 can do for me