- Home /
Question by
Jaishnu_R · Aug 26, 2020 at 10:59 AM ·
camera rotatey-axis
How to Rotate the camera up and down using mouse input.
My Code So Far:
float mouse = Input.GetAxis("Mouse Y"); Vector3 look = new Vector3(0, 0, mouse * 10); transform.Rotate(look);
Comment
Answer by rufopufo · Aug 26, 2020 at 11:26 AM
Hi,
Moving the camera up and down, means rotating around X axis.
Notice that 'Input.GetAxis("MouseY")' returns positive values whenever you move your mouse up. And negative values whenever you move it down. But, if you want to look Up with the camera, the rotation on the X axis goes down, and whenever you look down, the x value on rotation increases.
So, you have to invert whatever you recieve in your mouse variable:
float mouse = Input.GetAxis("Mouse Y");
transform.Rotate(new Vector3(-mouse*sensitivity,0,0));
You should do this in the Update method, so it gets automatically calculated every frame.
Hope it helps.