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