[SOLVED] Factory - spawned dynamic object's position change problem

Hi, I am using a relatively old(1.2.179) Defold engine. I am new to game development, lua and Defold. I am reading stuff from tutorials too, but I am sure that I missed something! My game structure is like that :

I am using single player.go file which can be “factory producible dynamic” (collision type) object. I used below code for factory (which has id player_factory : shown below inside main.collection ) :slight_smile:

spawner_script.script :

function init(self)
– Add initialization code here
– Learn more: https://defold.com/manuals/script/
– Remove this function if not needed
local pos = vmath.vector3(100, 100, 0)
self.player_id = factory.create(“#player_factory”, pos)
–print(“Spawned player id:”, player_id)
– move the spawned player
go.set_position(vmath.vector3(500, 500, 0), player_id)
end

But, spawned dynamic object positioned as it created once it produced location ( 100,100,0). I could not change its position by using “set_position()” inside init.

I used “kinematic”-player collision object type- but, “init” function’s code did not work again. But same set_position() code I use in “update” function finally moved “player” to (500,500,0)- correct position

I also used the same set_position code in update of “dynamic object” but not succeed. What did I do wrong? Thanks :slight_smile: Since inside init, could not do it, after it is spawned, how can I change its position then?

In the first screenshot you have

go.set_position(vmath.vector3(500, 500, 0), "sprite", self.player_id)

Which of the two versions of code are you actually testing with? The one in the screenshot is wrong.

If you want to spawn something using a factory and set it’s initial position then use the second argument to factory.create() to set the position:

self.player_id = factory.create(“#player_factory”, vmath.vector3(500, 500, 0))
1 Like

:smiley: Dear britzl, answer is that “not in the screen shot”. In the screenshot , I just tried to test whether sprite or go itself failed to change its location. Thanks.