What to do against camera/object- jittering?


So i have this key that follows the player. the player is clean but if the velocity is to high the key starts jittering on my PC. Any idea how to fix this ?
Camera is attached to the Player Node and Smoothing is off.
This Rubberband effect is done if one line of code

func _process(delta):
	if Gobal.player_has_key == false:
	elif Gobal.player_has_key == true:
		if Gobal.player_facing_right == true:
			follow_position = Gobal.player_position_vector + Vector2(-14,0)
			follow_position = Gobal.player_position_vector + Vector2(14,0)
		area_2d.monitoring = false

func following_animation(delta):
	get_tree().create_tween().tween_property(self, "position", follow_position, follow_time)

Screenshot 2024-07-10 214418

Probably best to not use a tween for animations that happen every frame.

you could use lerp if you do not care about frame dependency, or this function if you do

func exp_decay(a, b, decay, delta):
    return b + (a - b) * exp(-decay * delta)

func following_animation(delta) -> void:
    # play around with the number 16; a good range is 1 to 25
    position = exp_decay(position, follow_position, 16, delta)

— Lerp smoothing is broken by Freya Holmer

thank you! i never hear of leaps before, looks complicated for a beginner like me. But i watch this video later and give it a try

The lerp variation is pretty simple, usually gets mistakenly recommended over better animation tools. But in your case it might be what you’re looking for.

position = position.lerp(follow_position, 0.1)

This example takes position and makes it 0.1 aka 10% closer to follow_position. Done every frame it looks rather smooth, but it is frame dependant, meaning low-framerate computers would see a very different path from high-framerate players.

And you can see part of the lerp inside the exp_decay function, and the difference when they are side-by-side

func lerp(a, b, weight):
    return b + (a - b) * weight

func exp_decay(a, b, decay, delta):
    return b + (a - b) * exp(-decay * delta)
1 Like