Godot Version
4.3
Question
So, I am making a 2D top down game. However, my perspective isn’t as straight forward. It is an oblique projection.
So, that means that bodies will be rendered behind an object when they are left or above. However, objects that occupy a single tile that can be walked around cause an issue where the bodies will render behind it both left and right due to y-sort.
Is there a way to sort objects relative to another object without effecting how they are rendered relative to other other objects around them. So, z index doesn’t work.
I solved this problem with a project I did many years ago.
I sorted the rendering of the images based on their y2 cordinate. The images with the highest y2 on the screen render first.
You still would want to do layering, with the ground being layer 0, rendered first of all. Then your other layers, rendered according to the y2 on the screen.
So a y2 of 10 gets rendered before y2 of 20.
Y2 is the bottom of image texture.
It worked really well for this. It can be done in Godot, but not so easy and straight forward. You must put the sprites in layers to control their rendering order.
Another thing about my project, is it had a moving camera. Only the sprites inside the camera get sorted.
I am not familiar with the term y2, are you using it to refer to an exponent of 2 on the y coords? Sorry, first time running across someone writing that particular notation.
In the texture you have left top cordinate. Plus you have bottom right cordinate. The Y2 is the bottom of the texture.
Of course in Godot (0,0) should actually be the center of the texture or sprite. So you would want to use the sprites cordinate, Plus half the height of that sprite texture. This would be your y2 cordinate. The bottom of the image is what you sort them by.
The top most sprites on the screen get drawn first. This makes all the lower sprites overlap the higher sprites.