I have a parent and child object can they have a different z position? (SOLVED)

In my game I have a mother ship… There are top and bottom graphics for it.

The top (parent object) of the ship has a bottom (child object). I set the z position of each. I then set some smaller alien game objects to a different z position inbetween so they can appear to come from inside the mother ship. Doesnt seem to work…

In the parent I set…

	local p = go.get_position()
	p.z = ALIEN_LAYER + 0.01
	go.set_position(p)

In the child I set…

local p = go.get_position()
p.z = ALIEN_LAYER - 0.01
go.set_position(p)

So one layer is above and one below… the alien layer …

Remember that that the position is relative to any parent game object. The world position of a game object is the sum of positions of the object itself and any parent object positions:

ALIEN_LAYER = 10

TOP Z = ALIEN_LAYER + 0.01
 |
 +- BOTTOM Z = ALIEN_LAYER - 0.01

print(go.get_position("TOP").z) -- 10.01
print(go.get_world_position("TOP").z) -- 10.01

print(go.get_position("BOTTOM").z) -- 9.99
print(go.get_world_position("TOP").z) -- 20

In your case the BOTTOM layer is actually closer to the camera than the TOP, which is probably not what you intended?

1 Like

ahh so blooming simple… works a treat :star_struck: