how to separate nodes when they are added?

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

when I write this I am adding 10 new nodes instantiated to my scene, but they all appear in the same position. how I do to establish a certain separation between them?

  onready var scene = preload("res://Sprite.tscn")
    
    
     func _ready():
        	pass 
        
        
        func _physics_process(delta):
        	if Input.is_action_just_pressed("ui_accept"):
        		for i in 10:
        			var instance = scene.instance()
        			add_child(instance)

If you are talking about a 2D project and you just want to place them next to each other (instead of on top of each other), you could simply add this line below the add_child statement:

instance.position += Vector2(10,10) * i

Thomas Karcher | 2021-01-20 15:29

:bust_in_silhouette: Reply From: AnindyaRoy

Create a random number generator. After that before the add_child statement wirte var x = random number generator.randomise(range here probably or whatever the syntax is, check out the docs)
After that in nxt line type instance.translation.x = x
In next line type var y and reapeat it for instance.translation.y and translation.z if you have it or if you need it.

If you didn’t understand properly, check out godot docs for RandomNumberGenerator and you will get the idea of what to do