Jittery Movement Issues in Unity 2D Project

Hello everyone,

I’m experiencing some frustrating movement issues in all of my Unity 2D projects, and I’m hoping to get some advice. The issue occurs not only with regular sprites but also with UI images and even when I move the camera.

To troubleshoot, I’ve tried the following:

  1. UsingFixedUpdate for movement.
  2. Moving the camera updates to LateUpdate.
  3. Using Time.deltaTime to ensure a consistent frame rate.
  4. Adjusting quality settings (V-Sync and frame rate cap).
  5. Adjusting texture import settings.
    (6. Avoiding large memory allocations.)
    (7. Implementing incremental garbage collection.)
    (8. Avoiding complex calculations in the Update loop.)

Despite all these efforts, the issue persists.

So I created a completely new 2D project with only a single sprite and a camera! The camera has just this attached:

using UnityEngine;

public class SmoothCameraMover : MonoBehaviour
{
    public float moveSpeed = 5f; 

    void Update()
    {
        float moveX = Input.GetAxis("Horizontal");
        float moveY = Input.GetAxis("Vertical");

        transform.Translate(new Vector3(moveX, moveY, 0) * moveSpeed * Time.deltaTime);
    }
}

However, I’m still facing the same problem: A little movement followed by a noticeable jerk, then a little more movement followed by another jerk and so on. And I thought after all this years I wouldn’t face such basic problems… :frowning:

I’m using Unity version 2022.3.47f1. If anyone has any insights or suggestions on what else I could try, I would greatly appreciate it!

Thank you!

Make sure you have VSync enabled in the Game view.

Thanks! Sadly, for me, this didn’t Change a thing.

Not selecting the gameobject moving kinda helped in the test project tough.

But in all the other ones there must be a different reason, because … still stuttering…in the editor and in the build. :frowning:

Camera movement should be done in LateUpdate so it happens after all other transform and rigidbody changes have happened.

That said, try Cinemachine. No need to do the custom camera work yourself when Unity already has a fully featured package that does it for you.

:frowning: will give that a try, but I don’t have too much hope. The problem also occurs when I move the object instead of the camera. Additionally, I just found out that my ‘partial success’ isn’t actually true. I ran the same test project on my ‘big PC’ instead of my laptop, and now the problem is back, no matter what I do. And here too, I’m only trying to move a white square. It should somehow work with an RTX 4080. :smiley:

UPDATE: I don’t know if the problem is really ‘solved,’ but due to the different results on two different computers, I just played around with the graphics settings on my PC. For some reason, the refresh rate was set to 64 Hz. Now it’s set to 60 Hz. And so far… it seems to be working, at least in my test setup. I have the feeling that 3 million things cause stuttering, and sometimes all at once…:frowning:

If you can, upload an example project.

Unity wouldn’t be a usable engine if moving some sprites around was jittery.

And is it actual frame drops, or just a perceived jitter? If it’s frame drops, you can try using the profiler to see where the overhead actually is.

Are rigidbody’s involved? If so, have you configured them to use interpolation? And are you moving them via the rigidbody API?

Thanks again for the reply!

It’s not frame drops, which would be alarming in an empty project. :slight_smile:

And no, no rigidbodies. Just sprites, or UI images, or the camera. Not all at the same time, of course.

But … I tested it a bit more, and it seems like changing the framerate actually made the difference. That’s great for me, but shouldn’t it run smoothly even at “unusual” framerates? Later, the player would also be annoyed if it stutters for them because their system is running at 64 Hz. They wouldn’t be able to find the cause, just like me.

Is there anything I can do about it?

you should use OBS to record your screen, and post evidence of the jittering you are experiencing

for example make a video, then move the camera while recording

then open the video in vlc for example and use the “next frame shortcut” to take screen shots. and pickout 2 sequential frames where the movement from one frame to the other has artifacts that are undesirable.

This way you can properly show “what is happening” when there is movement VS “what should happen”

1 Like

Well the user won’t be playing your game in the Unity Editor so the first thing you should always do is try it in an actual build. The Editor has all sorts of overhead which you first need to discount.

Also to note, this isn’t a “2D-Graphics” thing i.e. not a 2D product area question; it’s a scripting/general-graphics thing. The same thing should happen no matter what renderer you’re using unless you’re saying it’s specific to a SpriteRenderer which I’d be very suprised if that were the case.

I don’t know why you’d try performing updates at the default 50Hz to make things smoother, that would be very odd.

You would always do this anything unless you’re controlling the the script execution order otherwise you might update your camera position before updating the target its following.

1 Like

I’ve tried all the solutions I found online and included them above. Since you receive various tips, whether helpful/logical or not, I added them to the list. But thanks for the clarification!

As I have no idea where my problem comes from, I wasn’t sure where to post it. Feel free to move it to the appropriate place.

Regarding the note about the editor: the issue also occurs in the build. I may not have made that clear enough.

And I’ll try to record a video as soon as possible!

Thanks!

EDIT: Dropbox

Like I said… it goes away when I switch to 60 Hz.

can you zoom it in and show specifically what part you think looks incorrect rendering?

for example look in this image:

https://imgur.com/a/6QX5Zfz

the problems are very apparent, the video you posted does not lend itself to easy spotting of artifacts

When looking at the video, you can notice a jolt every second/half a second or so. That’s what’s bugging me. :slight_smile:

I don’t see any jittering, sorry.

:flushed:

That’s SO not what I expected. :smiley:

Okay … here is the same Scene without the stutter ever 0.x seconds. How it should look like.

https://www.dropbox.com/scl/fi/wmypuwtozlx5orqsc3o1l/Desktop-2024.10.10-16.23.30.01.mp4?rlkey=mlacd6fak2y686cq0ek8ylvj8&st=kepwn46a&dl=0

you see the problem, you have to really zoom in and pinpoint exactly and objectively what looks wrong to you

slow down the video, zoom it in real close, make it go frame by frame

since you have the comparison of what it should look like, show very slowly and zoomed in, the problem happening

when you just show the square moving around, it doesnt look like anything

hope you understand, its hard to see what you want us to see if you dont show it like i said, I gave you an example also on how ppl make it SUPER OBVIOUS that something is going wrong in my above post with the mario sprite

That leaves me a bit speechless because I feel the difference is extreme. Like black and white. Choppy vs. smooth. Like you wouldn’t need to explain the difference between Sonic and a hedgehog run over by a truck. But I’m realizing now that only I seem to notice it, which is also a realization in itself. :smiley:

To avoid wasting even more of your time, I’ll just mark the change in Windows refresh rate to 60 Hz as the solution.

Cheers and thanks for the effort!