Godot 4: 3D Cards fanning

Godot 4.2.1

I just started working with 3d this week, and I thought a good exercise would be to recreate some 3d game as practice. I chose Inscryption.

The problem is with the card fanning. I don’t know exactly the problem but you see the gap between the cards, thats the problem. I want the cards to be centered with the hand_ratio but the cards just go to the far end.

(Video)

(ScreenShot)

(Code)

func organize_cards():

	for card in $Cards.get_children():
		var hand_ratio = 0.5
		var destination = $Cards.position
		var camera = get_viewport().get_camera_3d()
		
		if $Cards.get_child_count() > 1:
			hand_ratio = float(card.get_index()) / float($Cards.get_child_count() - 1) 
			
		destination.y = $Cards.position.x + spacing_curve.sample(hand_ratio) * 2.0
		
		destination.z = height_curve.sample(hand_ratio) * camera.basis.z.y
		
		card.position = destination

wouldn’t using variables for spacing be more useful instead of hard-coding it? that way you could practically make it so that when a card is added/discarded you can increase/decrease the spacing accordingly. I’ll try to give an example below but make sure to trust your gut because I honestly don’t know what I’m doing either.

@export var base_card_spacing := 2.0

func organize_cards():
	var card_count := $Cards.get_child_count()
	var spacing := base_card_spacing
	
	if card_count > 1:
		spacing /= float(card_count - 1)  # reduced gap with more cards
	
	for card in $Cards.get_children():
		var hand_ratio := 0.5
		var destination := $Cards.position
		var camera := get_viewport().get_camera_3d()

		if card_count > 1:
			hand_ratio = float(card.get_index()) / float(card_count - 1)

		destination.y = $Cards.position.x + spacing_curve.sample(hand_ratio) * spacing
		destination.z = height_curve.sample(hand_ratio) * camera.basis.z.y

		card.position = destination

again, sorry if there’s any inconsistencies. that’s all I could come up with