title: Jittery movement of the camera when rotating AND moving - 2D top down Unity
body: <p>I am making a 2d top down game where the player can rotate the camera around himself as he moves through the world.</p>
  
  <p>Everything works fine when the player is moving around the world the camera follows him fine. if he standing still then the camera rotation also works very well. However as soon as I start to do both then there is a jittery in the camera that makes all other objects jitter besides the player.</p>
  
  <p>Now in working with this problem I have found out that this could have to do with the fact that I use rigidbody2d.AddRelativeForce (so physics) to move the player and that his movements are checked in FixedUpdate.</p>
  
  <p><a href="https://forum.unity3d.com/threads/camera-jitter-problem.115224/" rel="nofollow noreferrer">https://forum.unity3d.com/threads/camera-jitter-problem.115224/</a> <a href="http://answers.unity3d.com/questions/381317/camera-rotation-jitterness-lookat.html" rel="nofollow noreferrer">http://answers.unity3d.com/questions/381317/camera-rotation-jitterness-lookat.html</a></p>
  
  <p>I have tried moving my camera rotation and the following scripts to LateUpdate, FixedUpdate, Update you name it. Nothing seems to work. I am sure that there is some sort of delay between movement of the camera and the rotation that is causing this. I am wondering if anyone has any feedback?</p>
  
  <p>I have tried disabling Vsync, does not remove it entirely
  I have tried interpolating and extrapolating the rigidbody and although there is a difference it does not remove it entirely. Ironically it seemd if I have it set to none, it works best.</p>
  
  <p>Scripts:</p>
  
  <p><strong>To Follow character, script applied to a gameobject that has the camera as a child</strong></p>
  
  <pre><code>  public class FollowPlayer : MonoBehaviour {
  
    public Transform lookAt;
    public Spawner spawner;
    private Transform trans;
    public float cameraRot = 3;
  
    private bool smooth = false;
    private float smoothSpeed = 30f;
    private Vector3 offset = new Vector3(0, 0, -6.5f);
  
    //test
    public bool changeUpdate;
  
    private void Start()
    {
        trans = GetComponent&lt;Transform&gt;();
    }
  
    private void FixedUpdate()
    {
        CameraRotation();
    }
  
    private void LateUpdate()
    {
        following();
    }
  
    public void following()
    {
  
        Vector3 desiredPosition = lookAt.transform.position + offset;
  
        if (smooth)
        {
            transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
        }
        else
        {
            transform.position = desiredPosition;
        }
    }
  
    void CameraRotation()
    {
        if (Input.GetKey("q"))
        {
            transform.Rotate(0, 0, cameraRot);
        }
  
        if (Input.GetKey("e"))
        {
            transform.Rotate(0, 0, -cameraRot);
        }
    }
  
    public void SetTarget(string e)
    {
        lookAt = GameObject.Find(e).GetComponent&lt;Transform&gt;();
    }
  </code></pre>
  
  <p>}
  <strong>The character Controller, script applied to the Player, is called in FixedUpdate</strong></p>
  
  <pre><code>      private void HandleMovement()
    {
  
        if (Input.GetKey("w"))
        {
            rigid.AddRelativeForce(Vector2.up * speed);
        }
  
        if (Input.GetKey("s"))
        {
            rigid.AddRelativeForce(Vector2.down * speed);
        }
  
        if (Input.GetKey("a"))
        {
            if (facingRight)
            {
                Flip();
            }
            rigid.AddRelativeForce(Vector2.left * speed);
        }
  
        if (Input.GetKey("d"))
        {
            if (!facingRight)
            {
                Flip();
            }
            rigid.AddRelativeForce(new Vector2(1,0) * speed);
        }
    }
  </code></pre>