Im making player health UI and Id like to move multiple sprites using tween to move like sine wave. I also wanna make it wave faster if player health is lower. I would appreciate if you could help me how to do it. With my code right now, the sprites doesnt move as expected.
extends CanvasLayer
@onready var player_health_bar01 := $crystal_heart1/Sprite2D as Sprite2D
@onready var player_health_bar02 := $crystal_heart2/Sprite2D as Sprite2D
@onready var player_health_bar03 := $crystal_heart3/Sprite2D as Sprite2D
@onready var player_health_bar04 := $crystal_heart4/Sprite2D as Sprite2D
@onready var player_health_bar05 := $crystal_heart5/Sprite2D as Sprite2D
func test_animation():
var tween = get_tree().create_tween()
var sprites = [player_health_bar01, player_health_bar02, player_health_bar03, player_health_bar04, player_health_bar05]
for sprite in sprites: # sprites should be a list of your sprites
tween.tween_property(sprite, "position", Vector2.UP * 20, 0.5).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN_OUT).as_relative()
tween.tween_property(sprite, "position", Vector2.DOWN * 20, 1).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN_OUT).as_relative()