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;
}