Search Unity

Help Wanted Pixel Perfect and jittering

Discussion in '2D Experimental Preview' started by simple421, Apr 23, 2021.

  1. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    My player and objects has jittering behaviour when i'm using "Upscale Render Texture" parameter in Pixel Perfect Camera. If damping equals to 0 then player is not jittering but surrounding objects are a little bit.

    GIFs:


    Objects settings:



    Code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Rigidbody2D))]
    4. public class PlayerMovement: MonoBehaviour
    5. {
    6.     [SerializeField, Min(0f)] private float _speed = 0f;
    7.  
    8.     private Rigidbody2D _body = null;
    9.  
    10.     private void Awake()
    11.     {
    12.         _body = GetComponent<Rigidbody2D>();
    13.     }
    14.  
    15.     private void FixedUpdate()
    16.     {
    17.         var move = new Vector3
    18.         {
    19.             x = Input.GetAxisRaw("Horizontal"),
    20.             y = Input.GetAxisRaw("Vertical")
    21.         }.normalized * _speed;
    22.  
    23.         _body.velocity = move;
    24.     }
    25. }

    Static objects snapped to the grid. Is there any way to fix this jittering?

    Unity version: 2021.1.0f1
    URP version: 11.0.0
     
  2. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Are you moving it by using physics?
     
  3. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    Yep. Movement code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Rigidbody2D))]
    4. public class PlayerMovement: MonoBehaviour
    5. {
    6.     [SerializeField, Min(0f)] private float _speed = 0f;
    7.  
    8.     private Rigidbody2D _body = null;
    9.  
    10.     private void Awake()
    11.     {
    12.         _body = GetComponent<Rigidbody2D>();
    13.     }
    14.  
    15.     private void FixedUpdate()
    16.     {
    17.         var move = new Vector3
    18.         {
    19.             x = Input.GetAxisRaw("Horizontal"),
    20.             y = Input.GetAxisRaw("Vertical")
    21.         }.normalized * _speed;
    22.  
    23.         _body.velocity = move;
    24.     }
    25. }
    edit: I tried to move player transform instead of rigidbody but jittering still here.
     
    Last edited: Apr 24, 2021
  4. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Ok have you tried to change the Update method to FixedUpdate in the Cinemachine inspector?
    Another thing you can do is to use the experimental PixelPerfect Camera that comes with the URP.
     
  5. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    Update method is set to SmartUpdate but I tried to set it to FixedUpdate and LateUpdate but it didn't help.

    I'm already using PixelPerfect Camera from URP package. Any other suggestion? I'm lost :(
     
  6. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Ok but, just to be sure, the picture you posted is using Cinemachine's PixelPerfect Camera, and you have replaced it with URP's later, is that right?
     
  7. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    It was URP from the start.
     
  8. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Ok I was referring to this component, you can give it a try
    upload_2021-4-24_13-14-42.png
     
  9. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    Sorry, I don't quiet understand what you want me to do. You want me to delete Cinemachine Pixel Perfect from VCam?
     
  10. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Exactly.
     
  11. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    And use the other component in the object of your camera.
     
  12. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
  13. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    Mmm that's strange, that worked for me (my game had camera jittering as well). They fixed the pixel perfect camera recently.
     
  14. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    Strange indeed. What is your unity version?
     
  15. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
  16. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
    The only difference I see is the Blending Mode.
    My Unity version is 2020.3.4.
     
  17. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    255
  18. simple421

    simple421

    Joined:
    May 17, 2019
    Posts:
    16
    I guess your objects aren't jittering because of the high reference resolution. I tried and it works for me but now rotation isn't pixelated.
     
  19. Coin9

    Coin9

    Joined:
    Feb 14, 2019
    Posts:
    16
    Obviously the jittery movement occurs because when using upscale render all the movements are happening at absolute integer values and theres no smoothing between these steps what really makes this feature useless unless you are using really high pixel resolution so that the steps are smaller and not so noticeable or you make some kind of shader that smooths the movement or use this technique discussed in this thread https://forum.unity.com/threads/pix...ization-for-seamless-camera-movement.1059041/
    Though i wish unity would add some sort of movement smoothing to the upscale render feature making it usable as ive not seen any or many games use this feature because of the jitter and these threads about pixel perfect jittering keeps popping up regular basis because of it.
     
    simple421 and ThundThund like this.
unityunity