This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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():

        func _physics_process(delta):
            if Input.is_action_just_pressed("ui_accept"):
                for i in 10:
                    var instance = scene.instance()
Godot version 3.2
in Engine by (196 points)

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

1 Answer

0 votes

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

by (50 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.