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. Dismiss Notice

Question Sprites are jittering while moving.

Discussion in '2D' started by Ujjawal49, Aug 25, 2020.

  1. Ujjawal49

    Ujjawal49

    Joined:
    Apr 26, 2018
    Posts:
    35
    Hello everyone, I need help, i have an issue with moving sprites in unity. Whenever I move them, the jitters. I have the sprites asset compression to none and it's filter mode is point(no filter).
    I am moving the sprite using this way :-
    Code (CSharp):
    1. public float speed;
    2. void Update ()
    3. {
    4. transform.position += Vector2.left * speed * Time.deltaTime;
    5. }
    It's a flappy bird clone.
    Here is a small sample project file (look at the pipes when they move towards the bird or at left of the screen in the project) :- https://drive.google.com/file/d/1DxWb-xBdVp1gf_G-HO70-Cz_HP7rk-r_/view?usp=drivesdk

    It's so annoying please help me.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    • Texture filtering modes and compression have nothing to do with smooth motion
    • Don't expect smooth motion in the editor, there are too many other things going on. Use builds to determine that. Vsync is the only sure way to perform super nice motion in a player build.
    • Do not modify the Transform when using physics objects. A Rigidbody2D is in charge of the Transform so you changing it isn't helping you at all. Use the API provide on the Rigidbody2D to move it. Your script sets the Transform rotation.
    I suspect your main problem is that you're expecting smooth motion in play modein the editor? Produce a build and run on a "quiet" machine. :)
     
  3. Ujjawal49

    Ujjawal49

    Joined:
    Apr 26, 2018
    Posts:
    35
    Hello and thanks for the reply but my actual problem is not smooth motion. The problem is with the shifting of pixels. You can see it in this gif :-

    So the problem here is the shifting of pixels while moving. Any ideas about it?
     
  4. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    Why would the camera be a child of the sprite?
    Why does the position keep changing + x?
     
  5. Ujjawal49

    Ujjawal49

    Joined:
    Apr 26, 2018
    Posts:
    35
    No actually it's not my project, just look at the girl who is in the right side. I gave this gif to show an example of jittering.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    Because you're moving fractional values (not pixels) then you need to use the pixel-perfect camera set-up with a low resolution configured to what you want. You can't move to 1051.042 and just expect it to be aligned to pixel.
     
  7. Ujjawal49

    Ujjawal49

    Joined:
    Apr 26, 2018
    Posts:
    35
    So are you talking about pixel perfect package that can be downloaded from the package manager and the. Use the pixel perfect camera component? One important thing, my camera is not moving, my sprites are because it's a flaapy bird like game.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    Yes if you want pixel perfect which you seem to want. You call it "jitter" but what you seem to be expecting is that the resolution of your sprite should be the resolution of its movement which isn't the case.

    Makes no difference. A camera moving right is no different than a sprite moving left with respective to both those things.
     
  9. adehm

    adehm

    Joined:
    May 3, 2017
    Posts:
    369
    I've build pixel games without a pixel perfect camera. Kind of confused by this; is this because op is snapping the sprite?