[SOLVED] How do I make object go front and behind other objects?

Hi!

I’m making a little topdown game. I’ve already set the player object to collide with the tree object when his Y is higher or lower than tree Y. Ok.

Now I’m struggling to make the player change its Z to lower value than Tree Z when it passes behind tree (PLAYER.Y < TREE.Y).

Initially the player starts with the highest Z value. So I added this line, and I don’t know why is not working:

Could you help me?

Thanks!

Your logic is sound, and you’re in luck, someone has already done this for you.

Check out the “Y sort” extension in the extension list.

Yeah, I’ve heard about it and tried it, but I couldnt find any tutorial online. I couldnt make ysort work by myself.

Am I doing it right?

I added the ysort behavior to both, player and tree.
Both objects are same layer
Player Z > Tree Z

what else shoud I set up?

It doesn’t have a tutorial as it isn’t configurable. You put the behavior it gives onto the objects you want to sort, make sure they’re on the same layer, and then they both sort based off the Y position of their Origin points.

So as your player moves down, as soon as their Origin Point’s Y position is “higher” (actually lower on the screen, because Y positions increase as you move south), it’ll appear infront of the Tree.

If it has a lower Y position, it’ll go behind the tree.

That’s what I did :pensive:

OK! I discovered what was going on and fixed it! Now it works!

Thanks a lot!

For furthers readers: remember setting the origin points corretly

2 Likes