[Solved] Code automatic Z-Order switching

This is one that I’m sure a lot of people would benefit from -

I’m making a top-down game and want to have the ability to make object be behind others (I changed the collision shapes to make this happen and changed the z-orders accordingly, to create the illusion that an NPC is standing behind the player, for example.)

So far, my code looks a bit like this:

If prop is above player, make prop’s z-order less than player’s z-order. (i.e. put prop behind player)
If prop is below player, make prop’s z-order more than player’s z-order. (i.e. put prop in front of player)

It’s more complex than that, but hat’s the gist.

Thing is, I have two controllable characters and a variety of NPCs, structures, mobs, bosses, items, etc that all need to follow something like this. So I have to make everything change z-order in relation to both player characters and also other NPC’s, Props, strustures, etc.

Am I over-complicating things? I probably am.

Anyway, I want to write a line of code that says something like

if any object’s y-position is greater than another object’s y-position - make (z-order of object with greater y-position) > than (z-order of object with lesser y-position)

I tried setting each object’s z-order equal to their y-position, but that didn’t seem to work.

What am I missing?

Hi! Usually, setting z order to Y should work. Check the origin point of the sprites, put them at their base / feet level.

It worked! So simple.
Thanks very much!