Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug Pixel perfect camera jittering on rotation

Discussion in '2D' started by togglerunner, May 22, 2024.

  1. togglerunner

    togglerunner

    Joined:
    Jul 4, 2022
    Posts:
    2
    Using a camera to follow the Player object (including rotation). It seems like rotating the camera beyond a certain threshold (about 47 degrees to either side) creates a very noticeable jitter. I have tried adjusting countless settings to no avail.



    Any help/suggestions would be greatly appreciated!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,571
    Camera stuff is pretty tricky... I hear all the Kool Kids are using Cinemachine from the Unity Package Manager.

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/

    If you insist on making your own camera controller, do not fiddle with camera rotation.

    The simplest way to do it is to think in terms of two Vector3 points in space: where the camera is LOCATED and where the camera is LOOKING.

    Code (csharp):
    1. private Vector3 WhereMyCameraIsLocated;
    2. private Vector3 WhatMyCameraIsLookingAt;
    3.  
    4. void LateUpdate()
    5. {
    6.   cam.transform.position = WhereMyCameraIsLocated;
    7.   cam.transform.LookAt( WhatMyCameraIsLookingAt);
    8. }
    Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.
     
    togglerunner likes this.
  3. togglerunner

    togglerunner

    Joined:
    Jul 4, 2022
    Posts:
    2
    Will try this and update. In any case, thanks a lot for the suggestion!