I have this compass that shows both your own heading (compass directions) and the heading of an object with an elk icon (the cube in the demo) with relation to your avatar (the wolf that’s right in front of you).
http://www.wolfquest.org/demos/compass_demo.html
It uses this code:
// this script is attached to the object containing the elk icon, which is in a layer with its own camera
var landmarkObject : GameObject;
var playerWolf : GameObject;
function FixedUpdate () {
var landmarkP : Vector3 = landmarkObject.transform.position - playerWolf.transform.position;
var playerH : Vector3 = playerWolf.transform.TransformDirection(Vector3.forward);
var angle : float = Vector3.Angle(playerH, landmarkP);
print (angle);
transform.localEulerAngles.y = angle;
}
This very nicely finds the angle between the player’s avatar and the cube object and then rotates the elk icon into place. What it doesn’t do is know whether that angle is to the left or right.
I am sorry to betray my ignorance of vector math, but I would greatly appreciate a hint about how to indicate whether the target heading is to the left or the right.
Thanks,
Steve