how to get current angel of a analog stick

as the title suggest im looking to get the current direction of analog input.

long and short im patching someone else code and in my changes I am adding controller input to a game that only has mouse input. I notice the rotation is handled with.

 Vector3 positionOnScreen = Camera.main.WorldToScreenPoint(transform.position);
angle = AngleBetweenTwoPoints(positionOnScreen, Input.mousePosition);
Quaternion newRotation = Quaternion.Euler(angle, 90, 90);
Vector3 newPosition = transform.position + (ShipDirection * Time.fixedDeltaTime);
newPosition.z = 0;
transform.rotation = newRotation;
 transform.position = newPosition;

as the name suggest AngleBetweenTwoPoints will calculate a float in degrees for angle to be inserted into newRotation = Quaternion.Euler(angle, 90, 90); ( comparing mouse position to player position )
when testing with a mouse the angles are calculated as

  • far right angle = 180 ,
  • far left angle = 360,
  • top of screen angle = 270 ,
  • bottom of screen angle= 450

so for constancy I can say

  • if x >0 angle= 180 ,
  • if x <0 angle= 360 ,
  • if Y >0 angle= 270 ,
  • if Y <0 angle= 450 ,

the part im stuck un is how would i get the in-between angles ?

so for example if the stick is pressed in the top right it should be an angle between 180 and 270 but how would I get the precise value from the current xy access .

any feed back would be appreciated

Maybe I’m naive, but can’t you just keep using the functions you have? Like: Take the individual Axis-Inputs of your controller, make them a Vector2 and then use the already existing Functions.

angle = AngleBetweenTwoPoints(Vector2.zero, myControllerVector)

Getting the Input depends on the system you are using. Legacy or InputManager.

Mathf.Atan2() and Mathf.Rad2Deg can give you every angle your heart desires.

using Legacy input but that part is not an issue , “Take the individual Axis-Inputs of your controller, make them a Vector2” I will have to double check the parameter of that function when I get a chance , I could be over thinking it , thanks

Mathf.Atan2() and Mathf.Rad2Deg , gassing Atan is the tangent from geometry ( never got a good grasp on that class) Rad2Deg speaks for its self good to know that is built in

thanks guys

It is an octant-corrected wrapper around Mathf.Atan() (inverse of tangent, or arc tangent)