I'm creating a 2d sidescroller, but quite different one. Every stage in my game has a fixed area on z axis and x axis that character can walk on. So that it's not like super mario that you can walk only right and left but you can also walk up or down. So I have 3 positions: on x axis z axis and y axis.
I'm facing now some problems connected with z buffer. I've got some obstacles in the stage that character can jump on. And there may be as many obstacles placed on each other as you want. So that in specified Z axis position there mgiht stand a tower consisting of 5 crates for example. And here's the problem. Every crate that is placed higher than former crate in such tower should be displayed closer to screen and character which is standing on it must be also displayed as it was always closer than the chest(though it doesn't have to be true becouse every obstacle has its Z axis walking area). In order to solve this I've done this:
1. I've created a variable for every object called obstacle_area and this variable is added to object's z buffer value before displaying it.
2. When any object collides with crate, I assign to this object's obstacle_area:
- the crate's value of walking area on z axis
- and this carte's own obstacle_area variable value
Thanks to this every crate is located higher in the tower than former one and displayes as it was closer and a character that jumps on the tower is displayed closer in every point that belongs to obstacle's walking area on z axis. Character standing on obstacle might have lower z position than the obstacle but is displayed as it was closer.
But due to this appeared one issue. Now the crate that is being on the top of all has its z buffer value increased by all the former obstacle_area values and its own walking area on z axis. In result towers that consist of 1 object but are as high as towers consisting of multiple objects are displayed behind those objects.
Here's normal image showing that crates display properly and character can stand even on the edge of top crate but it still displayes closer.

Here's picture showing that if the red tower(which is only 1 object) is placed on the lower z position (behind crates tower) everything's displayed good too

Here's picture showing the even if the red tower is placed on the higher z position crates(anything) being on top of the tower are displayed first which is very bad

I guess this issue is a bit complex so sorry if something is unclear. If so, please ask me and I'll try to provide more accurate info.
I would be really extremaly grateful if anyone could advice other solution or help me solve this issue!
Edited by savail, 02 August 2012 - 06:19 AM.






