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

#1

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

0 Likes

#2

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

#3

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

3 Likes

#4

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

0 Likes

#5

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

1 Like

#6

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

0 Likes

#7

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

0 Likes

#8


This is my brand new opened script that does not run

0 Likes

#9

Do you mean through main.collection?

0 Likes

#10

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.

0 Likes

#11

I did a ctrl+s just now but nothing changed

0 Likes

#12

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

0 Likes

#13

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

1 Like

#14

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:

0 Likes

#15

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

0 Likes

#16

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
0 Likes

#17

Without the )?

0 Likes

#18


It doesn’t work

1 Like

#19

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

0 Likes

#20

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

0 Likes