Factory spawned objects get euler.z from another object? (SOLVED)


Edit to add solution to the top: “[rotation] the rotation of the new game object, the rotation of the game object calling factory.create() is used by default, or if the value is nil”

I’m getting some very strange behaviour and I’m not sure if it’s a bug or a mistake on my end.

I have a spaceship that rotates to face the direction of the mouse cursor. As the player travels through space, I spawn “solar systems” in a grid pattern. It appears that the new solar systems that are spawned somehow inherit the euler.z property I set for the spaceship.

My collection proxy looks something like this:

The #script component of galaxy_player_ship sets euler.z as follows:

go.set(self.my_id, "euler.z", self.current_angle)

self.my_id is just a variable storing go.get_id() so I don’t have to call that over and over, the behaviour is the same if I replace it with go.get_id(). The rotation of the spaceship works as expected, and commenting out this line stops the problem I am having with the systems.

A lua module “system_generator” checks how far the spaceship has moved, and spawns new solar systems in response to movement. The solar systems are spawned like this:

local system_object = factory.create("system_factory#system_factory", game_utilities.universe_to_actual(system_details.universe_position + system_details.object_position))

I don’t think the problem lies in the game_utilities module, and checking the position/rotation of the system_factory game object reveals just the default position. I tried passing vmath.quat(0,0,0,0) as the
rotation argument when creating the object, but it appears to make no visual difference. Printing the rotation of the newly spawned object reveals 0,0,0,0 as expected, but visually it is still rotated. Without passing the argument, the printed rotation value is equal to that of the ship.

Since it is galaxy_player_ship that calls the system_generator module function to spawn systems, I thought perhaps the spawned objects somehow inherit the rotation from galaxy_player_ship. I moved the function call to an otherwise empty script, and turns out I was right. The objects now spawn correctly without rotation.

I guess I’m missing something? I suppose I’ve solved my problem but I’m in the early stages of designing this game and I’m really quite concerned that I am not understanding something fundamental here.



Try vmath.quat() instead of vmath.quat(0, 0, 0, 0).

For factory created objects to be affected by other objects they specifically have to parented with go.set_parent().

1 Like


Thanks @sergey.lerg

Tried vmath.quat() and it’s the same result as vmath.quat(0,0,0,0).

There must be parenting happening in some way, because I am just realising that the solar systems inherit the scale of the ship as well.

There isn’t a “go.set_parent()” anywhere in the project. Is there another way parenting can happen?

Seems this is either a bug, or I’m doing something so weird that I can’t even explain it right.



There’s also msg.post(url, “set_parent”).



Ah yes, that’s true! Okay - I can confirm that “set_parent” (or even “parent”) does not exist in any script in my project. :thinking:



The documentation for factory.create():

“[rotation] the rotation of the new game object, the rotation of the game object calling factory.create() is used by default, or if the value is nil”



Thanks @britzl.

Edit: Nevermind me. It was in fact what britzl’s post above indicated.

~Deleted a follow up post where I was mistakenly editing the wrong factory.create() line~ :man_facepalming:



Can you reduce this down to a very basic example to poke around in?



I should have just deleted my last post rather than editing to add “Ignore:” because the problem is solved. My initial issue was not passing anything to scale/rotation so your comment solved it. My most recent post was me being a dummy and editing the wrong line. :slight_smile:



Ah, got it!