Calculate Angle Problem

Hey guys, I’ve got a rather urging issue that needs solving! I made this function to calculate the angle on which the Y axis has to rotate to look at the mouse from top-down, but it doesnt seem to work =/ any ideas?

function calcAngle() : float {
	var oPos : Vector3 = transform.position;
	var mPos : Vector3 = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,Camera.main.nearClipPlane));
	mPos.y = oPos.y;
	var magX : float = mPos.x - oPos.x;
	var magY : float = mPos.z - oPos.z;
	if(magX < 0){magX = -magX;}
	if(magY < 0){magY = -magY;}
	var angle : float = Mathf.Atan2(magY,magX);	
	
	return angle;
}

why not just use lookat??

I need it to rotate ONLY allong the Y axis, LookAt uses all 3. I tried resetting the other axis, but that messes up the y rotation itself

Any ideas anyone? i need a solution fast, got a deadline for a minigame to be finished =3

http://forum.unity3d.com/threads/13785-Getting-the-angle-between-2-objects the post of podperson may interest you.

You might have just switched the 2 variables of the ArcTan. But that is just up to your Reference System. (Assuming you use X as radius of the Tan circumference, you should invert magY with magX).

Mathf.Atan2(magX, magY);

Might work.(Untested)

Philip