First person camera flipping by looking up or down too far.
So, I'm trying to make a first person camera, but there's a large problem with what little I have so far. The camera can currently bend over backwards to see things behind it upside-down :/ I have tried to fix this several different ways, but my inability to fix the problem keeps coming back to the fact that rotations are stored as quarternions... I'm fairly new to coding, so please forgive the question if it's noobish.
void Update ()
{
Camera.transform.Rotate(-Input.GetAxis("Mouse Y"), 0f, 0f, Space.Self);
Camera.transform.Rotate(0, Input.GetAxis("Mouse X"), 0f, Space.World);
}
Answer by AshleyX42 · Oct 27, 2017 at 08:13 PM
Update: So, I figured out that .eulerAngles will convert quaternions into euler degrees for me. I have made some progress with this information, but I'm now receiving a new problem. When X rotation is 0 degrees the camera will snap back to X being 90 degrees. I have no idea what's causing this. The camera won't look below 90 degrees so that's some progress... In the code below the camera is a child of the player.
void Update ()
{
rotateX = Mathf.Clamp(Camera.transform.localRotation.eulerAngles.x - (Input.GetAxis("Mouse Y") * mouseSensitivity), -90f, 90f);
rotateX -= Camera.transform.localRotation.eulerAngles.x;
Camera.transform.Rotate(rotateX, 0f, 0f, Space.Self);
Player.transform.Rotate(0f, Input.GetAxis("Mouse X")* mouseSensitivity, 0f, Space.World);
}