Godot Version
4.3
Question
Hey gamedevs, I’m almost near to achieve the circular inventory I want for my game like this one displayed in the image but I have a problem when displaying odd number of items
The display with a odd number of items (like 4) work as I expected
The problem appears when the item number is odd (like 5)
This is the code I use to adjust the items on the start and move items when action is just pressed:
func adjust_items() -> void:
var number_of_items = mini(max_items, items_container.get_child_count())
for index in number_of_items:
var angle: float = deg_to_rad(360.0 / number_of_items * index)
var x: float = radius * cos(angle)
var z: float = radius * sin(angle)
var child = items_container.get_child(index)
child.position = Vector3(x, 0, z)
inventory.append(child)
func next_item(direction: Vector2):
var inventory_size: int = inventory.size()
if inventory_size > 1:
var angleIncrement: float = 360.0 / inventory_size
for i in range(inventory_size):
var item = inventory[i]
var angle: float = deg_to_rad(angleIncrement * (i + direction.x))
var tween: Tween = create_tween()
tween.tween_property(item, "position", Vector3(radius * cos(angle), 0, radius * sin(angle)), next_item_spin_duration)