# Degree from point?

I want to calculate the degree of a touch location away from the centre of my screen. Currently I have this code:

``````var myVector : Vector3;
var myAngle : float;

function Update () {
if ( iPhoneInput.touchCount > 0 ){
for(var touch : iPhoneTouch in iPhoneInput.touches) {
myVector = new Vector3(240, 160, 0);
myAngle = Vector3.Angle(myVector, touch.position);
}
}
}

``````

The problem is that it doesn't really work. The degree's it comes up with are wrong and even if you do a full 360 loop around the point it doesn't exceed 50 at any point, does anyone have any idea why?

Daniel's answer is technically correct but will only give you 0-180 degrees.

If you want an angle that goes from -180-180 (i.e a full circle), you can use `atan2`.

I.e.

``````var myAngle : float;

function Update () {
var midScreenPoint = new Vector2 (Screen.width * 0.5, Screen.height * 0.5);
var dir = Vector3.Normalize (Input.mousePosition - midScreenPoint);
myAngle = Mathf.Atan2( dir.y, dir.x ); // myAngle is in radians
}

``````

How's this work for you?

``````var myAngle : float;

function Update () {
var midScreenPoint = new Vector2 (Screen.width * 0.5, Screen.height * 0.5);
var dir = Vector3.Normalize (Input.mousePosition - midScreenPoint);
myAngle = Vector3.Angle (Vector3.up, dir);
}

``````