Factory position and global position (SOLVED)

Hi, I issue a problem I don’t understand.
I have a game object with a factory component, localted on (0,0,0) position in my collection, when I spawn an object from that component, I make this object move to the opposite side of my screen, in a straight horizontal line, using go.animate.

Here is my problem, the spawned object goes diagonally, I printed the coordinates of each locations, the spawn location and the targeted location of the go.animate, and the Y coordinate is always equal…
For example :
spawn location : (0,480,0)
targeted location : (1280,480,0)

If the Y coordinate is the same how can it move on a diagonal?
I know the spawn location is relative to the game object holding the factory component but remember that this game object is located to (0,0,0) so the origin is the exact same point…

Thanks for reading :sweat_smile:

Sounds strange, could you maybe post your code for spawning game objects and animating them?

room_height and room_width are global and never change, it is just the seize of the screen

Choose a random position for spawning :

	local dice = math.random(1,4)
	--dice = 4
	local spawnpoint = dice
	local spawnpos
	if dice == 1 then
		spawnpos = vmath.vector3(0,room_height - room_height/3,0)
	elseif dice == 2 then
		spawnpos = vmath.vector3(room_width,room_height - room_height/3,0)
	elseif dice == 3 then
		spawnpos = vmath.vector3(0,room_height/3,0)
	elseif dice == 4 then
		spawnpos = vmath.vector3(room_width,room_height/3,0)
	end
	pprint(spawnpos)
        local newMob = factory.create("#bull_factory", spawnPos,nil,{},1.5)

Then I send a message to newMob with the “dice” value
The script on the spawned object get the message and set his self.originSpawn equal to the “dice” value he got in.

	if 	   self.originSpawn == 1 then
		goTo = vmath.vector3(room_width,room_height - room_height/3,0)
	elseif self.originSpawn == 2 then
		goTo = vmath.vector3(0,room_height - room_height/3,0)
	elseif self.originSpawn == 3 then
		goTo = vmath.vector3(0,room_height/3,room_width,0)
	elseif self.originSpawn == 4 then
		goTo = vmath.vector3(room_width,room_height/3,0)
	end

	go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, goTo, go.EASING_LINEAR, 2 , 0, move_charging)

As you can see it is a simple logic statement, nothing tricky :face_with_raised_eyebrow:

Can you check that you don’t run this code more than once? Your issue sounds like multiple animations are running at the same time on the same property.

I am sure that this code only run once, I checked it with print()

It behaves really oddly, I’ll try to describe it to you, you must know that actually my spawn locations and targeted locations are (0,240,0),(1280,240,0), (0,480,0), (1280,480,0)

I tried to move the game object holding the factory to (0,240,0) : the animated objects that were going from (0,240,0) to (1280,240,0) were moving the right way, and the objects going from (0,480,0) to (1280,240,0) were moving diagonally.
BUT
If I move my game object with factories on (0,480,0), the animated objects that are going from (0,480,0) to (1280,480,0) are moving the right way, and the objects going from (0,240,0) to (1280,240,0) are moving diagonally.

AND

Every object moving from x = 1280 to x = 0 are UNSEEN, I just don’t know where they are, I don’t see them on my screen, I have no way to see their real position in the game world :exploding_head:

If this problem seems too akward I can understand you surrender to solve it, to me it looks like a bug, maybe it is one but I am not sure, if there is no solution I can still think about annother solution, that would be heavier and less elegant but maybe funcitonnal

Are you nesting game objects/collections and what’s the position of the game object holding the factory?

I found it!

In fact all the monsters were spawning at the same place because I declared my spawnpos variable like

local spawnpos

instead of

local spawnpos  = vmath.vector3()

I didn’t know that declaring variables this way could make error happen…

Thanks for helping, I think I couldn’t find it without people to speak about it! :smiley:

2 Likes

If you pass in nil to the position argument of factory.create() the object will be spawned at the position of the factory. This is what happens in your first snippet of code.

If you pass in an empty vector3 (ie 0,0,0) the game object will be spawned at that position obviously.

2 Likes