I have balls in my res/assets folder with godot, I randomly assign these balls to the screen using gdscript codes, but a Node2D/Area2D/Polygon2D area has been created in my scene, I want the balls to come to the part of this polygon I specified, what should I do?
extends Node2D
var top_count = 0
var min_position = Vector2(50, 50)
var max_position = Vector2(350, 350)
var vertical_spacing = 30
func _ready():
func generate_random_position(tops, current_row):
var area_center = (min_position + max_position) / 2
var new_position = Vector2(
randf_range(area_center.x - (max_position.x - min_position.x) / 2, area_center.x + (max_position.x - min_position.x) / 2),
randf_range(area_center.y - (max_position.y - min_position.y) / 2 + current_row * vertical_spacing,
area_center.y + (max_position.y - min_position.y) / 2 + current_row * vertical_spacing)
)
for i in range(tops.get_child_count()):
var existing_top = tops.get_child(i)
var distance = new_position.distance_to(existing_top.position)
if distance < (existing_top.texture.get_width() + existing_top.texture.get_height()) * 0.6:
return generate_random_position(tops, current_row)
return new_position