I am creating a game in Unity 3d that is using a single joystick. I am trying to figure out how I can rotate a 3d object using the joystick correctly. Basically when the joystick is pushed up (or forward) the object will rotate forward and vice versa for when it is pushed down. My problem is getting the object to rotate correctly if I were to push the up diagonally to the left or right.
My joystick uses gives values (0, 1) for up, (0, -1) for down, (1, 0) for right, and (-1, 0) for left.
How do I get the object to rotate forward or backward and toward the diagonal direction on a joystick? (I'm sorry if this is confusing. I am trying to ask this as simple as I can).
Right now this is what I am using to rotate:
if ((x > 0 && x < .2f) || (x < 0 && x > .2f)) x = 0;
if ((y > 0 && y < .2f) || (y < 0 && y > .2f)) y = 0;
if (x < 0) car.transform.Rotate(car.transform.forward.x * 10f, car.transform.forward.y * 10f, -car.transform.forward.y * 10f);
else if (x > 0) car.transform.Rotate(car.transform.forward.x * 10f, car.transform.forward.y * 10f, car.transform.forward.y * 10f);
else car.transform.Rotate(car.transform.forward.x * 10f, car.transform.forward.y * 10f, 0f);