# How to rotate only Y Axis??

I have a joystick and i want my character only rotate in Y depending the joystick direction.
But i can´t make it.

``````float p = Mathf.Atan2(joystick.Vertical, joystick.Horizontal) * Mathf.Rad2Deg;
``````

I got the pending but only gives me values between -90 to 90.
And i need my character to rotate between 0 to 270.

My character moves:

up = 0

right = 90

down = 180

left = 270

I hope you can help a little with this. Thanks a lot

float angle= 0;
if (joystick.Horizontal > 0)
{
angle= 90;
angle-= 90 * joystick.Vertical;
}
else
{
angle= -90;
angle+= 90 * joystick.Vertical;
}

``````                Vector3 v = new Vector3(0, angle, 0);
transform.localRotation = Quaternion.Euler(v);
``````

Finally i got it. A friend help me to do it.

First we declare the angle to 0 and we check if our joystick is moving horizontal.

When it is bigger than 0 ( it means that the joystick is moving to the right ) so the angle to move my object to right is 90. So i put it 90 then that angle i subtract 90 * joystick.Vertical

So according to my angle that i expect to move in that way that is between 90 to 180 and 0. So only we need to multiply to the value of the vertical that it is between 1 to -1. So if it is positive, it means that the stick is moving up. And with the other is the same way.

Finally i get the angle to a vector3. That i make a Quaternion.Euler to make the rotation and i assign it to the rotation to my object.