Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

2D Platformer Pixel Art Slight Jittering during movement

Discussion in '2D' started by GazingUp, Jul 4, 2021.

  1. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    In my 2D platformer, there is slight jittering during my player's run. It's a pixel art game. I always assumed it was Cinemachine 2D causing it, but after removing the vcam/cinemachine brain and parenting the camera to the player, I still noticed jittering during movement. My movement code of the rigidbody is in FixedUpdate, my input is from Update. What else could be the reason for this kind of behavior?

    Movement Script:
    Code (CSharp):
    1.  
    2. private void FixedUpdate()
    3.     {
    4.         float h = character._moveH;
    5.         VelocityAdjust();
    6.         if (!runAllowed()) {
    7.             return;
    8.         }
    9.         if (h != 0)
    10.         {
    11.             character.state = CharacterController.State.Run;
    12.         }
    13.         else
    14.         {
    15.             if (character.state != CharacterController.State.Land)
    16.                 character.state = CharacterController.State.Idle;
    17.         }
    18.  
    19.     }
    20.  
    21.     void VelocityAdjust()
    22.     {
    23.         float h = character._moveH;
    24.         Vector2 newVelocity = new Vector2(character.speed * h, rigidbody.velocity.y <= -20 ? -20 : rigidbody.velocity.y);
    25.        rigidbody.velocity = newVelocity;
    26.     }
    27.  
    Input Script:
    Code (CSharp):
    1.  
    2.   void Update()
    3.     {
    4.         character._moveH = Input.GetAxisRaw("Horizontal");
    5.      }
    6.  
    Any help would be appreciated
     
  2. Tyrant7

    Tyrant7

    Joined:
    Aug 15, 2019
    Posts:
    34
    The most likely reason that this is occurring is because your player is moving in between pixels during their movement. I suggest taking a look at the Pixel Perfect Camera to stop this from happening, in the cast that you already are using Unity Pixel Perfect try enabling "Upscale Render Texture", which should round the pixels and stop them from moving in between the grid.

    Unity Pixel Perfect: https://docs.unity3d.com/Packages/com.unity.2d.pixel-perfect@1.0/manual/index.html
     
  3. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    Thanks for responding.

    I enabled a 'pixel snap' option in the player material and it seemed to have resolved the issue. I use URP that comes with an inbuilt 2d Pixel perfect camera.