title: Smooth Rotation - Quaternions
body: <p>I am trying to make a first person character controller and I am having an issue smoothing my look rotation. My <code>LookRotation</code> script takes my mouses input and uses it to rotate the character. I have used <code>Quaternion.Slerp()</code> in order to smooth my look rotation although there is an issue with using <code>Quaternion.Slerp()</code>. Once the desired rotation becomes larger than 180 degrees away from the current rotation it will just take the shorter route (the opposite way). The issue is in the last two lines of code. Does anyone have a method to prevent this issue? Thanks in advance!</p>
  
  <pre><code>#region Variables
  // Sensitivity variables
  [Range(0.0f, 10.0f)] public float horizontalSensitivity = 2.0f, verticalSensitivity = 2.0f;
  
  // Smoothing Variables
  [Range(0.0f, 30.0f)] public float smoothAmount = 5.0f;
  
  // Character rotation variables
  private Quaternion characterTargetRotation;
  private Quaternion cameraTargetRotation;
  
  public Transform character;
  public Transform characterCamera;    
  #endregion
  
  private void Update()
  {
      float horizontalRotation = Input.GetAxis("Mouse X") * horizontalSensitivity;
      float verticalRotation = Input.GetAxis("Mouse Y") * verticalSensitivity;
  
      characterTargetRotation *= Quaternion.Euler(0.0f, horizontalRotation, 0.0f);
      cameraTargetRotation *= Quaternion.Euler(-verticalRotation, 0.0f, 0.0f);
  
      character.localRotation = Quaternion.Lerp(_character.localRotation, characterTargetRotation, smoothAmount * Time.deltaTime);
      characterCamera.localRotation = Quaternion.Lerp(_characterCamera.localRotation, cameraTargetRotation, smoothAmount * Time.deltaTime);
  }
  </code></pre>