Comments and answers for "Mouse Look Script Not Working" The latest comments and answers for the question "Mouse Look Script Not Working" Comment by Robert_s_a on Robert_s_a's comment Sun, 12 Mar 2017 03:58:06 GMT Robert_s_a Comment by Robert_s_a on Robert_s_a's comment Sun, 12 Mar 2017 03:39:18 GMT Robert_s_a Comment by crazygamerdl1 on crazygamerdl1's answer Sun, 12 Mar 2017 03:21:10 GMT crazygamerdl1 Answer by Robert_s_a @crazygamerdl1 Hi, The problem you're encountering is because you are rotating around two axes, and once you have rotated even a little bit, the axes are now tilted, so subsequent rotations will tilt the horizon. This is much more apparent if you have something to look at. If you're interested in a visual of what is happening, you can create three cylinders called Xaxis, Yaxis, and Zaxis, scale them all to (0.1, 2, 0.1), and then rotate them in the Inspector so that they are pointing along each axis. (No rotation on Yaxis, (0, 0, -90) on Xaxis, and (90, 0, 0) on Zaxis) then translate them all to be at the same location as your camera. From there, in the hierarchy, attach them as children to the camera. From here, you can run your script and watch your camera tilt and turn in the Scene window. You'll see how combinations of rotations in X and Y will result in the whole thing turning and twisting, because you are rotating around axes that are tilted. If you're not interested, you can just proceed to the script below which will do what I think you are expecting. I did this using Quaternions and keeping a record of the total rotation you have input. Then I actually set the value of transform.rotation based on this quaternion. You can't plug numbers directly in this way without the quaternion .Euler transformation because quaternions aren't really numbers that humans use. LOL Anyway, basically I keep track of the total rotation you input, and send that in to your camera as if it were one rotation from (0,0,0) to wherever you have rotated to in total, rather than doing it in step by step increments which proceed from the last rotation. (I hope I'm not confusing you with this explanation as much as I'm confusing myself trying to type it) Essentially, you can spin left/right and up/down all you want, and the horizon will stay horizontal. Enough babble - on to the code. I'm in C#, so you'll have to tweak the syntax to get it into Java: using System.Collections; using System.Collections.Generic; using UnityEngine; public class TestCamera : MonoBehaviour { private float horizontalSensitivity = 10.0f; private float verticalSensitivity = 10.0f; private float v; private float h; private float totalV; private float totalH; private Quaternion tempRotation; void Start () { Cursor.lockState = CursorLockMode.Locked; } void Update () { // Read user input h = horizontalSensitivity * Input.GetAxis("Mouse X"); v = verticalSensitivity * Input.GetAxis("Mouse Y"); // Accumulate total rotation from all input to date totalV = totalV -= v; totalH = totalH -= h; // Calculate the single Quaternion rotation necessary to get us here tempRotation = Quaternion.Euler(totalV, totalH, 0.0f); // Apply that single rotation to the camera (from the origin) transform.rotation = tempRotation; outOfLock(); } private void outOfLock() { if (Input.GetKeyDown(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; } } } Hope this helps. :) Sun, 12 Mar 2017 02:03:00 GMT Robert_s_a