Understanding how z position within game objects affect the overall game rendering

Hi all, I have a game with:

  • A parallax GO, which consists in three layers
  • A player GO

Within the parallax GO, each layer is set to 0, 1 and 2 Z positions. In order to make my player to be drawn on top of the parallax, I must set it at least in the 6th Z position…why is that? How does Z positions within game objects affect the real world Z position?

Why the player is not drawn above the parallax if I put it in the 3 Z position, why from the 6th?

Another weird thing is that, if I put the parallax layers with a negative Z position…they are not rendered, just a black background…why?

And another more strange thing, if I run the game within the parallax collection the objects are rendered in the correct order, but if I run it from the main collection they are completely disordered!

Thanks.

In the default render script, z must be between -1 and 1. Values outside of that will not be rendered. You can modify the render script if you wish to change the range.

Z values are cumulative. If you have a game object with z 0.5, and inside that game object a sprite with z of 0.75, then the sprite will not be rendered (0.5+0.75=1.25 > 1).

3 Likes

Ok…I have done the following arrangements:

Parallax layer 0 - 0 Z
Parallax layer 1 - 0.1 Z
Parallax layer 2- 0.2 Z

Each one of the above game objects is in a collection called background, which is set in the main collection this way:

background - 0 Z
player - 0.3 Z

With your explanation and the values I have set, the player should be visible, but is drawn between the layer 1 and layer 2…

EDIT

I have removed the background collection and I have add it again to the main collection. For some reason, and with the same setup, now it works. So issue fixed, thank you!

1 Like