To find an object in front or behind I would use vector3.dot as in the following example:
public class example : MonoBehaviour {
public Transform other;
void Update() {
if (other) {
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 toOther = other.position - transform.position;
if (Vector3.Dot(forward, toOther) < 0)
print("The other transform is behind me!");
}
}
}
After toying with some of the variables, I seem to struggle in finding a way to detect if the object is either above or below my position. Would anyone be able to assist in accomplishing detecting whether an object is above or below.
Thank you