I want a compass needle to point to a target object offscreen. The compass is an upwards-facing arrow sprite in a Canvas, so will rotate on the Z-axis. The rest of the game is 3D.
From other answers here on UA I’ve made this calculation:
var dir : Vector3;
var angle : float;
var arrow: GameObject;
dir = target.transform.position - transform.position;
angle = Mathf.Atan2(dir.x, dir.z);
arrow.transform.eulerAngles = Vector3(0, 0, angle);
…but this doesn’t give the correct angle. Could anyone give me a pointer please?