How to spawn something at a specific position? (SOLVED)

Hey guys,
I have been programming a game for a while and was wondering how I make it spawn at a certain position.

I can’t help much without more details, but putting the following code in the script attached to your Game Object (and replacing x, y, z with the appropriate coordinates) should work:

go.set_position(vmath.vector3(x, y, z))
1 Like

factory.create’s second argument is the spawn position.

3 Likes

Ok, thank you for your time, I’ll try. Sorry for the lack of information, I was in a hurry. :slight_smile:

It doesn’t seem like the code is read at all. How do I fix this?

1 Like

Could you paste the code here? And could you add some print() to see if it’s getting near?

Have you added the script file as a component to some game object in your game collection?


This is my brand new opened script that does not run

Do you mean through main.collection?

Yes. On the image I can see that files are not saved (star indicator). If files are not saved, the changes are not visible to the engine.

I did a ctrl+s just now but nothing changed

Since it seems like you’re very new to Defold, I’d recommend checking out the tutorials.

Have you added the script file as a component to some game object in your game collection?

1 Like

I have now got everything to work, it is just the coding now. Thank you guys for all the help! I’ll probably ask you for more tomorrow to be honest. :slight_smile:

Great! So, what was the problem? :wink:

Note that the code in the screenshot is incorrect. It should be:

function init(self)
    factory.create("factory#snigel_factory", vmath.vector3(500, 170, 2))
end

Without the )?


It doesn’t work

1 Like

Use vmath.vector3(x,y,z) instead

Funkade ändå inte, ska jag ta bort min karaktär från main.collection först?