I'm not sure how you create the Car items now but if it's by GDScript, I would just position the items there.
# car item spawner
func spawn_car_items():
var car_items = []
# create 25 car items
for i in range(25):
var x = 0
var y = 0
var too_close = true
while(too_close):
x = randrange(600,1650)
y = randrange(-600,-390)
too_close = false
for item in car_items:
var other_pos = item.get_pos()
var x_diff = abs(x - other_pos.x)
var y_diff = abs(y - other_pos.y)
if x_diff < 32 && y_diff < 32:
too_close = true
break
var instance = CarItem.instance()
instance.set_pos(Vector2(x, y))
car_items.push_back(instance)
# car item
const carlist = ["car1","car2","car3","car4","car5","car7","car8"]
func ready():
# ideally you just call randomize once in your game at the start
# randomize()
var currentcar = carlist[randi() % carlist.size()]
getnode("carD").animation = currentcar
This code's not great but if you aren't running it too often, it should be okay. Another, probably easier, solution is to attach an Area2D
and use its get_overlapping_areas
method.