Search Unity

Simple 2D Parallax with orthographic pixel perfect cameras

Discussion in 'Cinemachine' started by zapposh, Oct 18, 2019.

  1. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    I am using URP with Pixel Perfect on my orthographic Main Camera, and the latest version of CM with the Universal Pixel Perfect extension on my VCams.

    My screens/Vcams are static and I blend from one to another when the player moves between screens.
    During these transitions, I would like a very simple parallax effect on the background plane (I cannot do this with a perspective cam -> orthographic & pixel perfect).

    A quick test as shown below leads to massive jittering of the background plane, even if I use LateUpdate instead of Update. It is a if the blend position interpolation value (Ease in/out)) is not the same as the real cinemachineBrain position value passed to the background plane.

    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         if (cinemachineBrain.IsBlending)
    4.             transform.position = (Vector2)cinemachineBrain.transform.position * depthCoefficient;
    5.     }
    Any ideas? Another way to approach this?
    Thanks.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The simplest way would be to hook into the event that's generated when Cinemachine positions the Camera. At that point, you should adjust your background, and it won't depend on the update method or any blends.

    Add a handler for CinemachineCore.CameraUpdatedEvent, grab the Brain's position, and use that to calculate the appropriate spot for your background layers.
     
    zapposh likes this.
  3. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    Works like a charm, thanks!
     
    Gregoryl likes this.