Does someone has an idea on how to make a fanning card animation

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

So I’m programming a card game and I want to the cards to fann out when in hand. I tried to make it by using an path2d node and 8 different pathfollower2d nodes and under every pathfollower i instanced a card, does someone have a idea how i can improve it that the animation is smooth and the cards doesnt have static position, for example that when there is just one card in hand that it goes automatically in the middle.

Perhaps create a Curve and calculate the card positions at points along its length and tween between the current position and new positions when adding/removing cards, a bit like this?

spaceyjase | 2023-04-05 15:22

ok thanks, but I need help with that because it’s not working i used the code from the youtube video and i deleted the path nodes and exchanged it with an simple node 2d which I named “Hand”

The Code:

func _process(delta):
	for CardInstance in $Hand.get_children():
		var hand_ratio = 0.5
		var destination:Transform2D= $Hand.global_transform
		destination.origin.x += CardCurve.interpolate(hand_ratio)* 2.0
		if get_child_count() > 1:
			hand_ratio = float(CardInstance.get_index()/float($Hand.get_child_count()-1))

DG_Games | 2023-04-05 17:50

I fixed it:

for card in $Hand.get_children():
	var hand_ratio = 0.5
	if $Hand.get_child_count() > 1:
		hand_ratio = float(card.get_index()/float($Hand.get_child_count()-1))
	var destination = $Hand.global_transform
	destination.origin.x += CardCurveWidth.interpolate(hand_ratio)* 50
	destination.origin.y += CardCurveHeight.interpolate(hand_ratio)* 25
	card.global_rotation_degrees += CardCurveRot.interpolate(hand_ratio)* 20
	card.set_global_position(Vector2(destination.origin.x, destination.origin.y))

DG_Games | 2023-04-06 12:51

Now I just need to tween it, but I dont have any idea how tweens work

DG_Games | 2023-04-06 12:52

Tweening is another skill entirely but worth the effort to learn. Good work so far, best of luck!

spaceyjase | 2023-04-06 13:38

Thank you for those inspiring words

DG_Games | 2023-04-06 13:58