Trouble setting object position when calling factory.create() (SOLVED)

Hello,

I am attempting to create an object with a supplied position. I have a script that creates an object via a factory and does not take the position I expect:

		local pos = vmath.vector3(400, 400, 1)
		print("creating enemy at " .. pos)
		local newId = factory.create("/EnemyFactory#factory", pos)

When it creates the object, it creates it at effectively (0,0,0).

Can anyone tell me what Im doing wrong? thanks.

1 Like

That is surprising. I can’t see anything wrong. What if you do go.set_position(pos, newId) on the line after factory.create()? What if you print(go.get_position(newId))?

1 Like

Is the sprite at 0,0,0 in the game object?

1 Like

So I added the lines:

        local pos = vmath.vector3(s.xPos, s.yPos, 1)
		print("creating enemy at " .. pos)
		local newId = factory.create("/EnemyFactory#factory", pos)
        -- new debug lines
		go.set_position(pos, newId)
		print(go.get_position(newId))

and the results I get are the box at the same position

and the following debug messages:

DEBUG:SCRIPT: creating enemy at [72.000000, 2500.000000, 1.000000]
DEBUG:SCRIPT: vmath.vector3(72, 2500, 1)

I will also mention that my GameObject has a gui component (with a red box under it) and a collisionobject component

I think I have fixed my issue. I realize while posting my previous post, I was using a GUI with a box in it to represent the enemy and I would probably be better off using a sprite

so I made an image and rigged a sprite to the Game Object I was using instead of a Gui, and now everything is working as intended. Im not sure about the interaction of go.set_position() with an object with a gui for a child but I think I have solved my problem.

thanks

Also for some reason all my other posts have been flagged as spam and hidden?

GUIs are (by default) rendered in a separate pass in screen space so the position of the game object you put the GUI component in does not matter at all.

Yeah, new users are flagged if more than 3 or so images are posted to the same url within some time limit. It’s Discourse default settings.

Thanks!

And individual gui components are moved in a .gui_script file attached to the .gui file using gui.set_position(node, position)