This is an issue I've been having with Godot since I've started using it for a pixel perfect game project: https://godotforums.org/discussion/26396/jitter-in-player-kb2d-over-moving-platform-kb2d#latest
I think I've understood completely the problem, now I need to find a good way to fix it.
It can be best exaplained with an example:
There's a platform (KinematicBody2D) moved by an AnimationPlayer.
There's a player (KinematicBody2D) moved with move_and_slide
.
Both use fractional increments for the movement because that's how AnimationPlayer and move_and_slide
work.
Everything gets rounded to the pixels in the screen in the last step of rendering into the viewport. Stretch mode
is set to "viewport" and Aspect
is set to "keep".
The issue happens when the platform is at a fractional value and the player is over the platform following its movement.
Say platform is at (50.2, 40), the player is at (50.3, 30) moved by the platform. On the screen, it gets rounded and the platform is at (50, 40) and the player at (50, 30).
Next frame the platform moves to (50.4, 40) and the player moves to (50.5, 30). Now the platform is at (50, 40) and the player at (51, 30) on the screen. The player is one pixel to the right respect to the platform since last frame because of the rounding at the rendering stage.
The same can happen with any two objects moving next to each other whenever the fractional parts aren't the same.
I'm trying to find a solution but I don't know of any way to force the rounding to be done before the physics processing.
I can try to match the fractional part of the player's position with the fractional part of the moving platform but I think there should be a better way. If the rounding was done before the physics came into play, this issue wouldn't exist.
Thanks for reading.
Edit: Test project in a comment below.