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

#1

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:
image

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.

0 Likes

#2

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

#3

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.

0 Likes

#4

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

2 Likes

#5

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:

0 Likes

#6

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”

2 Likes

#7

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:

0 Likes

#8

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

0 Likes

#9

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:

0 Likes

#10

Ah, got it!

0 Likes