# How do I properly rotate an FPS camera with a joystick?

So I’ve been looking around for quite a while now and it seems like there is no commonly understood way of using a joystick for FPS look controls. While I could find an endless number of FPS movement scripts and tutorials for mouse and keyboard I can not find one reliable script or tutorial to help me understand how to program look controls on a gamepad.

Here is the best I have come up with so far:

``````originalRotation = transform.rotation;
playerRotation = Quaternion.Euler(rightJoystickDirection.y, rightJoystickDirection.x, 0.0f) * originalRotation;
transform.rotation = playerRotation;
``````

Obviously this isn’t right, and it doesn’t even come close to working right, but again I’m at a loss as to how to use quaternions to rotate the player correctly.

What I really want to do is use a 2D vector (right joystick input) to rotate the camera a certain amount every second.

If anyone can point me to example scripts or tutorials that I can study to help get me closer to understanding what I need to know I’d be delighted.

Thanks!

Rotation of FPS camera using right analog stick.
i have a script for the camera rotation but have some issues with it.
the camera automatically rotates and never comes to rest .
i tried to manipulate my script but still get the same result.
here what i have done!

``````	private void tryjoy ()
{

Vector2 joyInput = new Vector2 (Input.GetAxis ("4th axis"),
Input.GetAxis ("5th axis"));

float camX = _camera.transform.localEulerAngles.x;

if ((camX > 280 && camX <= 360) || (camX >= 0 && camX < 80) || (camX >= 80 && camX < 180 && joyInput.y > 0) || (camX > 180 && camX <= 280 && joyInput.y < 0)) {
_camera.transform.localEulerAngles += new Vector3 (-joyInput.y * lookSpeed * .7f, _camera.transform.localEulerAngles.y,
_camera.transform.localEulerAngles.z);
}
transform.localEulerAngles -= new Vector3 (0, joyInput.x * lookSpeed, 0);
_yRotation = joyInput.y;
_cameraRefocus.GetFocusPoint ();

}
``````