- Home /
How to lock camera roll in C#
I'm trying to make my own mouse look script in C#, but I cant seem to figure out how to lock the roll in my script, the standard mouse look does it but mine starts to roll when I look up or down then left or right. I know the 3rd arg of transform.rotate() is the roll but I cant seem to make it stay 0.
Comment
Best Answer
Answer by cj_coimbra · Jan 26, 2012 at 11:51 AM
This is how I did it for my own mouse look (of course the numbers are only usable in my case, but you can adjust it to yours):
horizontalRotation = -Input.GetAxis("Mouse Y") * Time.deltaTime * CameraVerticalSpeed;
verticalRotation = Input.GetAxis("Mouse X") * Time.deltaTime * CameraHorizontalSpeed;
transform.Rotate(horizontalRotation, verticalRotation, 0);
transform.rotation = Quaternion.Euler(Mathf.Clamp(transform.rotation.eulerAngles.x, 11.22872f, 12.0f), Mathf.Clamp(transform.rotation.eulerAngles.y, 178.5f, 181.5f), 0);
Your answer
![](https://koobas.hobune.stream/wayback/20220613063420im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Uneven camera movement during roll 0 Answers
I want to create an interactive right analog MouseLook? 0 Answers
MouseLook.cs:case of JavaScript 1 Answer
Save Camera Rotation ERROR (HELP!!!!) 1 Answer
Fix MoveCamera can see body 0 Answers