How do I fix this menu level swipe that I made?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By David Wong

I’m making a menu level swipe, but there is a problem when shifting the card, the card seems to vibrate. is there something wrong with the code i made ?,
But when the card is set pivot_offset to a value of 0, the card becomes normal.

Thank you for your help

extends ScrollContainer

onready var margin_container: MarginContainer = $CenterContainer/MarginContainer
onready var card_node_list: Array = $CenterContainer/MarginContainer/HBoxContainer.get_children()
func _process(delta: float) -> void:
	var _center_pos: Vector2 = (rect_size / 2)
	for _card in card_node_list:
		var _card_pos = _card.rect_global_position.x
		if _card_pos > (_center_pos.x - 100) and _card_pos < (_center_pos.x + 100):
			_card.rect_scale = lerp(_card.rect_scale, Vector2(1, 1), 0.1)
			_card.rect_scale = lerp(_card.rect_scale, Vector2(0.7, 0.7), 0.1)

:bust_in_silhouette: Reply From: Mario

While I didn’t test it in code, I’m pretty sure your issue is caused by the offset moving with changed scale (so it’s hopping back and forth all the time, crossing the “border” where scaling changes). With no offset set, you’re scaling (0, 0), so nothing happens. But if you scale (1, 0), you’ll make it start moving/hop around.

To solve this, I’d simply make the visible card a child node of an invisible/default Node2D. You reposition and check the parent node’s position, but you actually scale (and never move) the child node showing the card.

thanks bro, I understand now. Now the card I made is smoother :smiley: :smiley:

David Wong | 2021-04-13 22:58