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:
UsingFixedUpdate for movement.
Moving the camera updates to LateUpdate.
Using Time.deltaTime to ensure a consistent frame rate.
Adjusting quality settings (V-Sync and frame rate cap).
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…
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!
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.
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…
It’s not frame drops, which would be alarming in an empty project.
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.
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”
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.
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!
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.
To avoid wasting even more of your time, I’ll just mark the change in Windows refresh rate to 60 Hz as the solution.