Sphere
Log in Join
☆ 14

characterbody2d jitters when standing still on moving platform

Godot 4.1.3, 2D platformer. My player is a CharacterBody2D with move_and_slide and when it stands on a moving platform (also a CharacterBody2D moving via velocity) the sprite jitters up and down by like 1 pixel every frame. The platform moves horizontally using velocity.x = 40 in _physics_process. Player has a floor snap of 8. I read somewhere that you need to add the platform's velocity to the player's velocity when standing on it. How do I detect the platform I'm standing on? get_slide_collision? I tried floor_constant_speed but that didn't fix the vertical jitter. Am I missing something obvious here?

⚑ Report

4 replies

☆ 0
P plastic2 ·2026-11-04#1

You need to inherit the platform motion. In 4.x there's no get_floor_velocity like 3.x; you get the floor body from get_slide_collision(i).get_collider() and read its velocity. Add that to your velocity before move_and_slide. The jitter is the player being left behind for one frame then snapped back by floor snap.

⚑ Report
☆ 0
K kernel55 ·2026-11-06#2

get_slide_collision works, but collider comes back as a Node and I have to cast it. I'm doing: for i in get_slide_collision_count(): var c = get_slide_collision(i); if c.get_collider() is Platform: velocity += c.get_collider().velocity. That fixes horizontal drift but the 1px vertical jitter remains. The platform only moves in X so I'm confused why vertical is jittering.

⚑ Report
☆ 0
F fern ·2026-11-09#3

That vertical jitter is probably your sprite/camera, not physics. If the camera follows the player with lerp in _process (not _physics_process) and physics ticks at 60 while your monitor is 144hz, you get sub-pixel camera positions that round differently each frame. Put camera follow in _physics_process with a fixed lerp weight and round the final camera position to whole pixels.

⚑ Report
☆ 0
P paper ·2026-11-11#4

It was the camera lerp in _process. Moved it to _physics_process and rounded to int, jitter gone. For anyone finding this later: the platform-velocity thing is still worth doing even after fixing the jitter, otherwise the player slides off when the platform moves fast. Both problems, two fixes. Godot docs don't make this obvious.

⚑ Report
Log in to reply.