+1 vote

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)
        else:
            _card.rect_scale = lerp(_card.rect_scale, Vector2(0.7, 0.7), 0.1)

swipe-level-menu
enter image description here
enter image description here

Godot version Godot v3.3 rc7
in Engine by (73 points)
recategorized by

1 Answer

+1 vote
Best answer

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.

by (242 points)
selected by

thanks bro, I understand now. Now the card I made is smoother :D :D
enter image description here

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.