- Home /
Question by
CryFan001 · Dec 19, 2018 at 03:28 AM ·
camerarotationcamera rotate
Object rotates on an axis I don't want
So, I want to make an fps camera. So far, I got this:
void Update()
{
float horizontal = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float vertical = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
Transform camera = transform.Find("Main Camera");
camera.rotation = camera.rotation * Quaternion.Euler(-vertical, horizontal, 0);
}
However, when I move my mouse around, it also rotates on the z axis which makes it look weird. Is there anyway I could fix this?
Thanks alot!
Comment
Answer by Cornelis-de-Jager · Dec 19, 2018 at 05:25 AM
Rotate the transform on the horizontal axis instead of the camera's this will stop that weird sideways rotation:
camera.rotation = camera.rotation * Quaternion.Euler(-vertical, 0, 0);
transform.Translate (new Vector3(0, horizontal, 0));
Your answer
Follow this Question
Related Questions
How to fix weird camera rotation? 0 Answers
Top down camera for object moving on sphere 1 Answer
Set camera rotation around point in 2D 3 Answers
maximum angle for camera 0 Answers