Search Unity

Other Camera panning issue

Discussion in 'Editor & General Support' started by RRvfx, May 5, 2023.

  1. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    Hi everybody,

    I have an issue when panning the camera.
    It slightly stutters or jitters or flickers. it is a bit but it is still visible.

    Basically I have just updated the project from Unity 2021.3.11 LTS to 2022.2.17.

    No changes in code, no changes in compilation or quality settings (all it is exactly the same).

    It seems to me that this line of code is not working nice and smoothly as with previous Unity version:

    Camera.main.transform.position += offset;

    I have been trying to use Lerp or SmoothDamp, moving the code in LateUpdate or FixedUpdate but nothing produce the same smooth panning as before.

    It seems it something related with Unity? New API that I missed? What else?

    Can anyone suggest where to look for the solution?

    Thanks and regards
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Unlikely.

    More likely with the new version your game might be running at a slightly faster or slower framerate and it is making the stuttering more noticeable. It was probably always there. In general camera stuttering has to do with:
    • not moving the camera in cadence with frame updates
    • A mismatch in the cadence of your camera movement and the movement of the thing it is tracking
    • stuttery motion of a tracked object.

    To help find the source of the stuttering you'd have to explain to us:
    • How your camera is set up (e.g. are you using cinemachine? a custom camera script?)
    • How the object your camera is following is moving (Using rigidbody? Custom script? Both?)
    • The code for any and all of the above.
     
  3. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    Hi @PraetorBlue ,

    thank you for your quick answer.

    Well, this is what we do.
    We want the camera to follow two fingers movement on the screen in any direction (we are in a 3D scene), simply as that.

    In the phase of TouchPhase.Began we set a startPanPos like this:

    Code (CSharp):
    1. ...
    2. Vector3 PointFromPlane()
    3. {
    4.         //we interpolate to get the position in the middle of the two fingers
    5.         Vector2 p = Input.touches.Length > 1 ? Vector2.Lerp(Input.GetTouch(0).position, Input.GetTouch(1).position, 0.5f) : Input.GetTouch(0).position;
    6.         Ray tPos = Camera.main.ScreenPointToRay(p);
    7.         Plane ground = new Plane(Vector3.forward, new Vector3(0f, 0f, 0f));
    8.         float distance;
    9.         ground.Raycast(tPos, out distance);
    10.         var v3 = tPos.GetPoint(distance);
    11.         return v3;
    12. }
    13. ...
    14.  
    15. ...
    16. if (Input.touchCount > 1 && Input.GetTouch(1).phase == TouchPhase.Began) startPanPos = PointFromPlane();
    17. ...

    And then in Update (when TouchPhase.Moved happens) we simply do this:

    Code (CSharp):
    1. Vector3 direction = startPanPos - PointFromPlane();
    2. Camera.main.transform.position += direction;
    Please, share your opinion about a better way.

    Thanks