title: Unity inconsistent camera rotation with mouse
body: <p>So far learning unity, camera rotation with mouse is the thing that has given me the most problems. Now the problem I am facing is, when making a first person controller based on rigidbody, that the rotation of the character and camera with the mouse is inconsistent and jittery.</p>
  <p>This <a href="https://youtu.be/Cu97YI13AHY" rel="nofollow noreferrer">youtube video</a>, shows the problem. In it, i am smoothly moving the mouse but the rotation seems to sometimes skip some intermediate rotations and jump to new values.</p>
  <p>This is the hierarchy I am currently using for the character as well as the attached components:
  <a href="https://i.stack.imgur.com/N7CiG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N7CiG.png" alt="Image showing the hierarchy and attached components of a rigidbody based character" /></a></p>
  <p>And this is the complete code for the script</p>
  <pre class="lang-cs prettyprint-override"><code>    using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
  
      [RequireComponent(typeof(Rigidbody), typeof(Collider))]
      public class CompleteRBController : MonoBehaviour
      {
      [Header(&quot;Referenced components:&quot;)]
      [SerializeField]
      private Rigidbody _rb;
      [SerializeField]
      private Transform _cameraTransform;
  
  
      [Header(&quot;Mouse Settings&quot;)]
      public float _mouseSensitivity = 100f;
      [SerializeField]
      private float pitch = 0f;
      [SerializeField]
      private bool _mouseInverted = false;
  
  
      [Header(&quot;Parameters:&quot;)]
      [SerializeField]
      private float _speed = 10f;
      [SerializeField]
      private float _sprintSpeed = 15f;
      // Start is called before the first frame update
      void Start()
      {
          Cursor.lockState = CursorLockMode.Locked;
      }
  
      // Update is called once per frame
      void Update()
      {
  
      }
  
      private void FixedUpdate()
      {
          //Get input mouse
          float mouseX = Input.GetAxisRaw(&quot;Mouse X&quot;) * _mouseSensitivity * Time.fixedDeltaTime;
          float mouseY = Input.GetAxisRaw(&quot;Mouse Y&quot;) * _mouseSensitivity * Time.fixedDeltaTime;
  
          //Get input keyboard
          float vertical = Input.GetAxisRaw(&quot;Vertical&quot;);
          float horizontal = Input.GetAxisRaw(&quot;Horizontal&quot;);
  
          // Debug.Log(string.Format(&quot;Vertical: {0}, Horizontal: {1}&quot;, vertical, horizontal));
  
          bool isSprinting = Input.GetKey(KeyCode.LeftShift);
  
          //Rotate
          pitch += (_mouseInverted) ? -mouseY : mouseY;
          pitch = Mathf.Clamp(pitch, -89, 89);
  
          _cameraTransform.localRotation = Quaternion.Euler(pitch, 0, 0);
          transform.Rotate(transform.up * mouseX);
  
          //Move
          Vector3 move = (transform.forward * vertical + transform.right * horizontal).normalized * ((isSprinting)? _sprintSpeed : _speed);
          _rb.velocity = new Vector3(move.x, _rb.velocity.y, move.z);
      }
  
  }
  </code></pre>
  <p>I will also add a list of things I tried to change to make it smooth:</p>
  <ul>
  <li>Changing getAxisRaw with getAxis. No effect on the smoothness of the camera movement.</li>
  <li>Lerping the vertical rotation. Adds too much delay, does not really seem suitable for FPS controller? How would I lerp the yaw?</li>
  <li>Move the rotation from FixedUpdate to Update. Does not do anything, and we are editing a rigidbody so it would be still better to do it on fixedUpdate with all other physic related calculations.</li>
  <li>Make separate components one for the rotation and the other for the movement. does not help either.</li>
  </ul>
  <p>Sometimes on the first seconds of the simulation i does work smoothly but after a little while it becomes wonky again.</p>
  <p>I dont really know how to fix it / what is causing the problem. I would really appreciate it if you could help me with this or put me in the right track to understanding the problem.</p>
  <p>Thanks in advance for helping me.</p>