Inconsistent z ordering when z coordinate is a fraction

#1

I’ve made a few cards using @Dragosha’s script (see Why is label invisible when rotated between 270 and 360? (SOLVED) ) and a factory which works fine, if the z index of the main card objects are a whole number.

issue1

However since I am using a perspective rendercam camera moving objects on the z axis will make them bigger, so if I have a lot of cards the card on the right will be somewhat bigger than the card on the left. Therefore I decided to reduce the z coordinate of every card by dividing the number by ten. This included the card game objects and every object inside the card as well. So my card’s z went from 1 to 0.1 and the text inside went from 0.5 to 0.05 and so on. This unfortunately causes a z order war, but I can’t understand why (z order is not always consistent between renders).

divided

	collectionfactory.create('/camp1#cards', vmath.vector3(-100, 0, 0.1), nil, nil, size)
	collectionfactory.create('/camp1#cards', vmath.vector3(0, 0, 0.2), nil, nil, size)
	collectionfactory.create('/camp1#cards', vmath.vector3(100, 0, 0.3), nil, nil, size)
	collectionfactory.create('/camp1#cards', vmath.vector3(120, 0, 0.4), nil, nil, size)

(The table in the background has a negative z coordinate)
Thanks for the help

0 Likes

#2

How did you go about doing that?

0 Likes

#3

In the collectionfactory.create('/camp1#cards', vmath.vector3(-100, 0, 0.1), nil, nil, size) I changed vmath.vector3(-100, 0, 1) to vmath.vector3(-100, 0, 0.1) . That’s for the card. For the objects (sprites/labels) in the card I simply replaced the numbers in the editor.

If I don’t divide the z in the factory, and only divide the z in the objects than everything is fine, but that’s not what I want.

0 Likes

#4

Remember that the positions of the components inside the game object are relative to the game object itself.

What are the sprite Z and the Label Z values?

0 Likes

#5

Large Sprite container is at 0
Sprites:

  • White Cover: 0.02
  • Parrot: 0.01

Game object that contains labels: 0.05
Labels are at 0
Game object that contains small sprite icons: 0.05
Icons are at 0

I think I’ve read it somewhere that the z coordinates are added up

So first label should have z value of 0.1+0.05 = 0.15
First white cover: 0.1+0.02 = 0.12
Second label: 0.2+0.05 = 0.25
Second white cover: 0.2+0.02 = 0.22

0 Likes

#6

The coordinates for the card objects are a bit weird, but this much should be fine
DEBUG:SCRIPT: vmath.vector3(-100, 0, 0.10000000149012)
DEBUG:SCRIPT: vmath.vector3(0, 0, 0.20000000298023)
DEBUG:SCRIPT: vmath.vector3(100, 0, 0.30000001192093)

I’m not sure how I could get the real Z coordinate from inside a factory spawned object

0 Likes

#7

I have changed everything with a z coordinate into a game object and replaced my factory with three instances.
Now I can print out the Z values, which seem to be okay.

0 Likes

#8

@Mathias_Westerdahl do you have any ideas, why this is happening? Is it because of the perspective camera?

0 Likes