# How do i get joystick angle and distance from its origin place?

tried this but not working:

``````var joystick : Joystick; //part of the script.
var V1 : Vector2;
var V2 : Vector2;
private var P : Transform;

function Start () {
V1 = new Vector2(joystick.position.x,joystick.position.y);
V2 = new Vector2(P.position.x,P.position.y);
}

function Update () {
P.position.y = joystick.position.y = 0;
P.position.x = joystick.position.x = 0;
var Di = Vector2.Distance(V1,V2);
var An = Vector2.Angle(V1,V2);
transform.rotation.y = An;
transform.position.z += Di;
}
``````

Use Input.GetRawAxis() to get number between -1 and positive 1 for each axis.
Multiply that by the maximum deflection angle for your stick.

The magnitude of the position (joystick.position.magnitude) is effectively it’s distance fom it’s centre.

The angle can be calculated using the atan2 function: angle = Mathf.ATan2(pos.x,pos.y)

However that function gives you an angle in radians. To get it in degrees, multiply it by Mathf.Rad2Deg