I was watching a tutorial on how to make an FPS controller. According to the tutorial, I had to use this code for my mouse look code
float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity;
float mouseY = -Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
rotY += mouseX;
rotX -= mouseY;
rotX = Mathf.Clamp(rotX, -90, 90);
//rotate cam and orientation
transform.rotation = Quaternion.Euler(rotX, rotY, 0);
orientation.rotation = Quaternion.Euler(0, rotY, 0);
Despite it working perfectly in the tutorial, when I playtested my controller, the mouse was inverted. I fixed it by changing it to:
float mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivity;
float mouseY = -Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivity;
rotY += mouseX;
rotX += mouseY;
rotX = Mathf.Clamp(rotX, -90, 90);
//rotate cam and orientation
transform.rotation = Quaternion.Euler(rotX, rotY, 0);
orientation.rotation = Quaternion.Euler(0, rotY, 0);
I’m not sure why the tutorial tells me to add the input values to my rotation floats and I’m afraid that my edit to the code may come back to bite me later.
Can someone please explain why the mouse is inverted or why I need to add the input to my rotation floats. Thx!