I need help with Z positioning

I want the object to be behind the avatar if the avatar’s Y position is greater than the object’s Y position. It works but only with the object with the greatest Y position; the other objects don’t work. I am aware on why it’s doing it but I don’t know how to fix it.


Change the z order of the object

first, dont change everything’s Z order. you should use “static” objects like trash cans or vending machines, and “active” objects like the player sprite. I think the life will be esier. so, you set up all the static objects Z once when they spawn to the world, after that only the moving object needs to change it’s Z.

secondly, I haven’t a mathematical formula to this. may be this tutor will hekp you: https://www.youtube.com/watch?v=UgB79LS-juQ

and thirdly If I want to create a game with similar perspective to this (I wanted it once), I would bring it closer to the 3D games. in 3D usually all objects origin above its foot, so they can adjust to the ground. but in a 2D game we hadn’t ground and the object’s origin is it’s top left corner. however, if we reposition all(!) object’s origin to it’s bottom center, I think we can use they “Y” coordinate as Z. for example in your screenshot: if player’s soles above the bottom of the trascan, hes “Y” is greater. and if Y=Z, his Z will be greater than the trashcan’s Z.

so i hope someone knows a mathematical solution to your problem, because set up all origin will mess up your project.

1 Like

There is a behavior in extensions for z-order.

I got back and checked it, Yeah all I had to do is change the order of the objects from the Z order. Thanks Guys

That perspecive is called 3/4 perspective and is the most used in classic RPG games of the 16bit videogame era.

3 tips for the type of perspective you are using in your game:

  • Set the origin point of each object at the base. I mean, at the place where it touches ground. For example, in the case of the character, set the origin point at their feet.
  • Then make the Z position of each object equal to its Y position value (this can be done once at scene start for the static objects and continously for the moving objects, like the player).
  • Make the collisions masks of the objects to cover just the theoretical three-dimensional base of the object. In the following picture, the green zones shows the collisions masks of each object:


In this way the objects will always overlap consistently with the perspective.

Here is a simple example of a character moving in 3/4 perspective and passing in front and behind objects:

3/4 perspective z-positioning


Be sure to take a look at the tweaked collision masks and origin points of the objects to see how it works.


Thanks a bunch!

I was searching all over the net and here lay my answer!

1 Like