0 votes

Greetsing! I seem to have a code (see below) which doesn't properly position an object. I load the function in the process(delta). Tried printing the position and everything seems to be ok. Any help would be greatly appreciated. Thanks!

ps I'm using Godot 2.1.3(old version)

func load_human():
var humans = human.instance()
var xpos 
var ypos  
for i in range(human_count):
    xpos = rand_range(1, 1020)
    ypos = rand_range(1, 760)
    humans.set_pos(Vector2(xpos, ypos))
in Engine by (44 points)

If I understand this code correctly then you create a single instance of human and then add the same instance multiple times as child (of what, the scene root?). Adding the same child multiple times sounds strange.

So you set the position and name of this same instance multiple times. And it should be visible on the last position set.

I can just guess that you actually want to create multiple instances in the loop. In that case I would create the instance inside the loop.

You say also, that you call this function from _process(). That would mean that the number of added_childs will explode as you will add multiple instances on each frame (i.e. 60 frames per second).

As you didn't tell it, I have no idea what you actually want to do but usually such a call is usefull on _ready() or at a certain (single) event.

HI! You're correct on that. I did transfer the human.instance() inside, and everything worked perfectly. Thanks for the reply wombat, much appreciated.

1 Answer

0 votes

For anyone having the same issues, I just transferred the var humans = human.instance() inside the loop and everything worked.

by (44 points)
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 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 webmaster@godotengine.org with your username.