Hey guys. I've been wrestling with a tricky problem and am wondering if anybody's got any bright ideas.
I'm working on a 3/4 perspective top-down game (eg. like A Link To The Past, or Stardew Valley) where the perspective is faked by sorting objects by Y value (a pretty standard technique to allow the player to walk in front of / behind trees, rocks, coins, etc as necessary).
This is working well, but now I'd like to add elevated platforms... and I'm getting confused.
I know a lot of old 2D games would completely fake the effect with art (eg the "elevated" parts wouldn't really be elevated, they would just be drawn to look that way):
The reason why I don't want to do that is that in those games, the back wall of the cliff would be a hard barrier that you couldn't walk behind, which kind of breaks the visual effect imho.
Ideally, I'd want the player to be occluded behind the cliff when standing behind it, but also to be able to stand on top of it - and to have all other game objects correctly Y-sorted at the same time.
Here's a (very quick and scribbly) image to illustrate what I mean (objects drawn in red would be subject to Y-sorting):
I considered making the cliff with its 'elevated' ground a separate layer above the normal ground layer, and moving the player object between layers based on invisible triggers when they enter or exit the ramp. Then each layer would have correctly Y-sorted objects at each level of elevation.
Except that wouldn't work for Y-sorted objects on the ground plane that would need to occlude the elevated ground (such as the foreground tree in the illustration above).
Another option might be to do everything on the same layer, but treat the cliff itself (or at least the back wall) as something that itself needs to be Y-sorted. I don't think this would work as Y-sorting is based on the y-sorted object's origin point, so anything "on top" of the cliff (such as the coins illustrated above) would be liable to get sorted behind the cliff since the y-value would technically be lower than that of the cliff base. And so on.
I really have no idea what the best way of doing this is and would be extremely grateful to anybody who has any ideas?
Many thanks...!