Search Unity

Cinemachine 2D Pixel Art Background Jittering

Discussion in 'Cinemachine' started by GazingUp, Feb 28, 2021.

  1. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    my background parallax is getting messed up because of Cinemachine's damping. I couldn't figure out why/how to fix it.


    It occurs right at the end of the movement, when the camera's catching up to the new position due to the damping. Notice the trees jitter.

    Here's the parallax script:

    public class Parallax : MonoBehaviour
    {
    public Transform cam;
    public float relativeMove = .3f;
    public bool lockY = false;
    private void FixedUpdate()
    {
    if(lockY){
    transform.position = new Vector2( cam.position.x * relativeMove, transform.position.y);
    }else{
    transform.position = new Vector2( cam.position.x * relativeMove, cam.position.y * relativeMove);
    }
    }
    }


    The virtual camera's using a framing transposer, the camera brain is using SmartUpdate for its update and late Update for its Blend update method.

    Player object's got no interpolation (I've tried all previously mentioned methods of using interpolation or not - doesn't work), player's movement is in Update, uses velocity.

    I read something about clamping pixels but I couldn't get it to work. My sprite's PPU is 32.

    Any help will be appreciated - this has been driving me up the wall for the last few days.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You are probably reading the camera's position before it gets set. Cinemachine updates the camera as late as possible in the frame. You need to read the transform after that happens. Try setting your script execution order to be after CinemachineBrain.
     
  3. Samdogg7

    Samdogg7

    Joined:
    Jun 14, 2015
    Posts:
    2
    Circling back on this issue - I was able to resolve it by setting the Blend Update Method to Fixed Update (previously Late Update) in my CinemachineBrain. My parallax calculations were done in the Update function of my parallax script.
     
    sederfan likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If that works for you, ok, but it doesn't sound like the correct solution. Instead, you should move your parallax calculations to be done later in the frame, after the Brain's LateUpdate.
     
    Zealot2018 likes this.
  5. sakamoto-kun

    sakamoto-kun

    Joined:
    Dec 11, 2019
    Posts:
    5
    this solution worked for me, thanks
     
  6. Zealot2018

    Zealot2018

    Joined:
    Jan 24, 2016
    Posts:
    5
    thank you.I set the parallax script order to be after all cinemachine scritps,set palyer's rigidbody2d interpolate on,move parallax sprite code to LateUpdate,finally get a acceptable outcome, still a little jitter for the very far parallax though.