• 2D
  • Jitter in player (KB2D) over moving platform (KB2D)

Hi.

I'm using KB2D for the player, and move_and_slide_with_snap inside _physics_process to move it. It's a pixel perfect demo with GPU pixel snap on.

The moving platform is another KB2D animated by an AnimationPlayer node. It has Sync to physics on and Process Mode set to physics in AnimationPlayer.

Most of the time, when the player lands on the platform it jitters, as if the player is moving ahead of the platform by one pixel from time to time. Sometimes, readjusting the player position by making a tiny movement can make the jitter disappear. I suspect that the use of floats for the position of the player and platform is causing the problem. When rounding to pixel positions on the screen they might be offset by up to 1 pixel depending on the result of the roundings in the player and platform.

Might i be right in this assumption? Any way to fix it?

Thanks.

EDIT: Improved the explanation a bit in hopes it gets me some answer.

Do you think there's something wrong with using floats for a pixel perfect game?

My demo is a flick-screen type of game. I've looked at the platform demos but they don't seem to have this problem because the platform and player don't move together across the screen. Instead, it's the camera that moves and thus the world around them is what moves across the screen.

I've confirmed that float rounding is the source of the problem by changing the position of the player when it lands on the platform to integers relative to the position of the platform. Thay way both are moving synchronously in the screen.

This is the code that implements the workaround:

	var collisions = get_slide_count()
	for i in collisions:
		var collider = get_slide_collision(i).get_collider()
		if collider is KinematicBody2D and collider.name == "Platform":
			delta = position - collider.position
			delta.x = floor(delta.x)
			delta.y = floor(delta.y)
			position = collider.position + delta

Now I'm wondering and trying to find tutorials/examples about how a pixel perfect flick-screen could be implemented using integer coordinates with smooth movement at variable frame rates.

I think there is an option in the project settings to enable pixel-snapping, but I do not remember what it is called right off. Enabling it may help with the visual jitter though.

@TwistedTwigleg said: I think there is an option in the project settings to enable pixel-snapping, but I do not remember what it is called right off. Enabling it may help with the visual jitter though.

Do you mean Use GPU pixel snap? It's already on. I've used the search box to look for any other "snap" options in the project settings but there's non except the same option for the GUI.

@berarma said:

@TwistedTwigleg said: I think there is an option in the project settings to enable pixel-snapping, but I do not remember what it is called right off. Enabling it may help with the visual jitter though.

Do you mean Use GPU pixel snap? It's already on. I've used the search box to look for any other "snap" options in the project settings but there's non except the same option for the GUI.

Yeah, I think that is what I was thinking! Shame it doesn't seem to fix the issue, since it's already on.

For anyone with a similar problem, I've found these related issues: https://github.com/godotengine/godot/issues/35606 https://github.com/godotengine/godot/issues/41491

These issues are still present in Godot 3.x.

See https://github.com/lawnjelly/godot-snapping-demo/ for a good summary on the problem and current solutions.

Thanks to golddotasksquestions in this thread for the help: https://www.reddit.com/r/godot/comments/np0g9f/pixel_perfect_movement_without_scroll/