[SOLVED]Moving platforms and jittering

Godot Version

4.4

Question

Hi guys! I’ve been working on a simple platformer for which I’ve made my own pixel art assets (they’re not great but, you know, doing my best :slight_smile: )

Right now, I’m creating some moving platforms and I’m working on the vertical moving ones and here I have a problem : a very ugly “jitter”/“noise” (I don’t know how to call it) appears when my character stands on them.
Here is a video of what I’m talking about :
https://streamable.com/xsu9zi

At first, I was moving the platform through tweens, I imagined that was the problem so I changed and moved the position directly and rounded the position of the platforms. But nothing is changing anything.

Here is the script for my moving platform :

class_name VMovingPlatformComponent
extends Node

@export_group("Nodes")
@export var me : AnimatableBody2D

var point_to_reach_bottom : int = 0
var point_to_reach_top : int = 0
var real_pos : Vector2 = Vector2.ZERO
var moving_down : bool = true
#var tween : Tween

func _ready() -> void:
	real_pos = me.position
	point_to_reach_bottom = real_pos.y + me.moving_distance_pixel # position + 32
	point_to_reach_top = real_pos.y - me.moving_distance_pixel # position -32

func _process(delta: float) -> void:
	if moving_down : 
		to(delta)
		if me.position.y >= point_to_reach_bottom : 
			moving_down = false
	else : 
		and_fro(delta)
		if me.position.y <= point_to_reach_top : 
			moving_down = true

func to(delta : float) : 
	#tween = create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
	#tween.tween_property(me, "position", Vector2(me.position.x, (me.position.y + me.moving_distance_pixel)).round(), me.time_sec).set_trans(Tween.TRANS_LINEAR)
	#tween.finished.connect(and_fro)

	real_pos.y += me.speed * delta
	me.position = real_pos.round()
	
func and_fro(delta : float) : 
	#tween = create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
	#tween.tween_property(me, "position", Vector2(me.position.x, (me.position.y - me.moving_distance_pixel)).round(), me.time_sec).set_trans(Tween.TRANS_LINEAR)
	#tween.finished.connect(to)

	real_pos.y -= me.speed * delta
	me.position = real_pos.round()

I’ve left the tween version (commented in the code) …Well, i’ve read a few threads on google and on this forum but I couldn’t find any solution so if you have ANY ideas, feel free to reach out!

Thanks a lot!

Marraw

What might be causing the issue is the round() function used for the real_pos float. Rounding would remove the positions in-between the whole number positions.

Sync the animated body to physics by using _physics_process instead of _process.

Use CharacterBody2d for your moving platforms especially if your player is a physics object. It was designed specifically for this use case, in fact, it has specific settings for moving platforms.

Thanks for the suggestion! I tried without the round() function but it didn’t make any difference sadly. Actually, my first script was without and I read about this function when I was looking to correct this “stuttering” effect but as you point out, it’s not good with OR without…

Thanks for the suggestion, I’ll try in code but I have this option checked on my animatableBody so I figured it was the same thing :

1 Like

Hi everyone!
To try and find out what’s going on, I changed a few things : the movement script was in a “component” so for testing purposes, I moved it on the AnimatableBody.
I remove the round() function and the movement logic is called in the _physics_process now.
I also removed any unnecessary things (the real_pos variable and the tween comments).
But for now, I can’t see no changes, in good or bad…
Here is the new code :

class_name MovingPlatformClass
extends AnimatableBody2D

@export_group("Settings")
@export var time_sec : float = 1
@export var moving_distance_pixel : float = 32
@export var speed : float = 10


var point_to_reach_bottom : float = 0
var point_to_reach_top : float = 0
var moving_down : bool = true

func _ready() -> void:
	point_to_reach_bottom = position.y + moving_distance_pixel # position + 32
	point_to_reach_top = position.y - moving_distance_pixel # position -32

func _physics_process(delta: float) -> void:
	if moving_down : 
		to(delta)
		if position.y >= point_to_reach_bottom : 
			moving_down = false
	else : 
		and_fro(delta)
		if position.y <= point_to_reach_top : 
			moving_down = true

func to(delta : float) : 
	position.y += speed * delta
	
func and_fro(delta : float) : 
	position.y -= speed * delta

I’m going to try to change the type from AnimatableBody2D to CharacterBody2D and keep you posted!

Thanks for your time!

Hi all!
Well, the solution to my problem was this : I had to UNCHECK the snapping in the project settings…

Now, everything looks good : Watch Enregistrement de l'écran 2025-02-27 101046 | Streamable

Thanks again for your time!

1 Like