How do I prevent this stuttering

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pgregory

I’ve seen various questions about this issue, but no conclusive answers that work for my case, which is about as simple as it’s possible to get. I find it difficult to believe that this is an actual issue that cannot be solved, it’s so fundamental to 2D games.

If I move a sprite in code in the _process(delta) function, using the delta to control speed, the result is unacceptably “stuttery” or “jerky”. I’ve created as simple an example as I’m able to here, https://github.com/pgregory/godot3_tests/tree/master/stutter, which is simply a sprite, being moved across the screen.

If you run that, you’ll see that rather than a smooth continuous movement, it stutters at irregular intervals.

This is currently a showstopper for a 2D game I’m working on, so any advice very gratefully received.

I also encounter such issue. However, when I actually build the project to a standalone version, the stutter disappeared. Don’t know why it stuttered when running in the editor though.

Chao Yu | 2018-03-29 08:20

:bust_in_silhouette: Reply From: Zylann

This happens in every game, even those not made with Godot, when they use V-sync, especially in editor/debug mode. This can be noticed in many games if you pay attention (and as such, isn’t always a show stopper).

An exported game will be less likely to have the problem due to more optimizations being turned on.
You can also disable V-sync, which makes the problem disappear (at least on your example).
A downside of doing this is that you might experience screen tearing when the scene scrolls, because it will basically make your game run as fast as it can.

I tried turning v-sync off, didn’t make any difference to me. The effect is even more pronounced in the real game, which unfortunately I cannot share.

I’m not sure I agree that all games suffer with this. I’ve played many many many side-scrolling jump and run games, never seen it before, if I had it would have driven me insane.

Can you explain why having v-sync on should cause this? The demo is running at between 280 and 300 fps, so even with v-sync on, it should be fine, I can’t see any logical reason for the movement to stutter the way it does while running at that frame rate.

pgregory | 2018-03-29 13:10

The demo is running at between 280 and 300 fps, so even with v-sync on, it should be fine

You can’t run a game at this speed with V-sync because V-sync caps framerate at 60 (or whatever your monitor refresh rate is), which means it is more likely to drop frames if there is any tiny delay (the cause can be very diverse on a PC).

I am not 100% sure what really causes the stutter, but I noticed it in many games I played (currently Factorio), so this is not a new problem and not specific to Godot.
I know that disabling V-sync makes it go away because I just tested it with your example.

It could be related to your driver, maybe?
There are issues opened on Github about this problem:
https://github.com/godotengine/godot/issues/2043
https://github.com/godotengine/godot/issues/10388

Zylann | 2018-03-29 15:35

Thats is not completely true, yes games made in other engine might have some stuttering but its not as noticeable and doesn’t happen this frequently, I’ve experienced the same problems with Godot but I can’t say the same of Unity and Game Maker Studio, in those engines simple projects like this one look very smooth.

FabianLC | 2018-09-27 13:00

:bust_in_silhouette: Reply From: leonardon

Hello @pgregory,

Did you conclude something from this?

I started a similar discussion here:

https://godotdevelopers.org/forum/discussion/comment/25017/#Comment_25017

I would appreciate if you could share what actions you took.

Did you fix it or did you stop using Godot… What happens?

No, haven’t found a solution yet, in fact it’s getting worse. I continue to try, but at the same time am porting my game to Unity to hedge my bets.

Paul

pgregory | 2018-09-09 08:23

It very well may not help you if you have to stay in v2, but this was supposed to be mitigated in the master branch. Would be interesting to see if you have the same issue. I guess you could even try recreating your prototype in the 3.1 alpha. Check out the bottom of the first link that Zylann posted for info.

2D||!2D | 2018-09-09 21:10

I’ve download the “stutter” project and tried it in 3.1 beta - same problem. It stutters with v-sync on and stutters differently with v-sync off. I’m having a similar problem with a 2D pixel based game when moving the camera, that’s how I ended up here.

René Ruppert | 2019-01-08 17:17

:bust_in_silhouette: Reply From: Cerno_b

I’ve had the same problem which annoyed me to no end, since I really loved the transition from GameMaker to Godot. Unfortunately, GM used to have butter-smooth animation, and Godot just felt jaggy even for toy examples.

I’m still on the lookout for what the actual root cause of the problem is, and I came across this very interesting article: https://medium.com/@alen.ladavac/the-elusive-frame-timing-168f899aec92

It seems like this could at its core be a problem of synchronization between CPU and GPU and it’s not Godot-specific but in fact a common, hard-to pin down problem faced by GPU-based engine developers.

That being said, I have only started using Godot so I need more experience about how it may be possible to mitigate this problem. I launched your example project and it displays the same stutter that I was able to see in my own projects, so I feel you.

I’ve had some success with leaving VSync on and setting the VSync Via Compositor option to true. The article mentions that this can often be the cause of stuttering, and the setting prety much solved the problem in your demo for me.

It’s beautifully smooth now sitting at precisely 60 FPS.

Note however that the tooltip for the compositor setting says that it is experimental and can cause frame rate halving.

:bust_in_silhouette: Reply From: Calinou

If you use Godot 3.2 or later, install, enable and configure lawnjelly’s smoothing-addon. This adds physics interpolation which should solve most jittering issues.