Object behaves differently when collectionfactory creates it [solved]

When I create my 3D dice in my main.collection manually. It works fine. But now I need to create it from a factory and the die is a collection so I use a collection factory.
image

When the collection factory die goes to the left side of the scene it disappears. In the video I have one manually created die and two collectionfactory dice. You can see how they behave differently.

If I try to spawn the object on the left side of the screen it won’t show up. Only the right side of the screen allows the object to stay on screen.

Any idea why this is happening? And better yet how to fix it?

1 Like

If you run the example you see that the x and y positions are suddenly changed to high numbers. In your code you have this check:

			if dice1_pos.x < 0 or dice1_pos.x > self.screen_width or 
			dice1_pos.y < 0 or dice1_pos.y > self.screen_height then
				go.set_position(vmath.vector3(self.screen_width / 2, self.screen_height / 2, dice1_pos.z), self.dice1)
			end

Remember that you are rendering using a perspective camera so you can’t simply check positions against the width and height used in game.project and if you reposition something using display width and height it is likely to end up off screen.

Select your dice in the main.collection and move it along the x-axis. You will see that the collision box you’ve set up spans from -18 to +15.

1 Like

Yes I noticed it gets wild coords.

I’m not following though. Why did it work on the manually added dice but not the factory collection?

Is it because the location of the parent object of the due?

Thank you. I just slid my entire scene to the right of the axis and now it works fine. I’m just confused why this didn’t behave the same way when the dice are manually added to the collection.

But you are only doing the position check on the two dice spawned through the collection proxy. The one that you’ve manually added to your collection has no position checks in the code?