Left and right rotation angles/targets

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

Just make a cross product of your vectors and see if the result points up or down. Up is left and down is right.

Thanks, Talzor. I’m going to end up learning vector math in spite of myself. It worked like a charm.

Best,
Steve

I just found a free (GFDLed) online book on linear algebra: A First Course in Linear Algebra. Maybe that will come handy.

The page also contains links to more free textbooks.

Thanks, Keli – I downloaded the book and now have even more reading!