Hi,
I have faced an issue and have no more ideas on how to fix it properly, so I hope someone here might be able to help me. Here is my problem :
In our game, we have a store with a lot of shelves. Customers come in and out, and pick some of the items.
We want all the items to be displayed on the shelves, independently, and they must be displayed properly (masked by some parts of the shelves, like the side, the top or the middle). We’d like to put a lot more items than what is on the screenshot below.
We also want the shelf itself to be displayed properly, appearing in front of or behind units as they come.
It is important to notice that many moving objects (customers) are going here and there and so everything should be rendered properly all the time.
Before adding the items slots in the shelves, I had a working system, inspired by those 2 blogs :
- https://breadcrumbsinteractive.com/two-unity-tricks-isometric-games/
- https://www.gamasutra.com/blogs/MartinPane/20170309/290889/What_I_learned_from_trying_to_make_an_Isometric_game_in_Unity.php
Basically, I play with the rendering order of the SpriteRenderer of every object to display things properly :
protected override void UpdateSortingOrder() {
spriteRenderer.sortingOrder = -(int)(objectTransform.position.y * YFactor);
}
And I do the same with a sorting group when there are added sprites to the object (cf the birdhouse example of the first link)
But as you can see in the 2nd link, this is not enough. When objects aren’t squares (equally wide as they are thick), the sprites must be splitted to be displayed properly.
And apart from being awfully annoying to do (because I would have tried to automate it at some point), it worked pretty good.
But the items are bringing a bigger problem. Because the shelves aren’t very thick, but they are wide, they need to be split in many parts.
The items are rendered like the birdhouse, so they need a pivot, a parent, to tell what is their Y reference for the rendering order.
If the shelf wasn’t splitted, no problem! But it is, and that means we need to pick a pivot amongst the different sprites of the shelf.
The problem stands when the item isn’t completely inside a part. because then, a part of the shelf is going to be displayed on top of it, or the characters going too close might see the item being displayed in front of them.
As you can see on this drawing, the slots are sometimes cut in half by the red lines, which correspond to the sprite splitting of the shelf. That means those slots are broken, there is no way the item in it is going to be displayed properly.
Right now, the only solution I see is to constrain the art/design to try to avoid those problems. Things like making the shelves thicker, spacing the items more. But honestly I hate it.
A friend of me proposed to go 3D for the sprite rendering, but I couldn’t find a way to make that work.
I am not against 3D, but keep in mind that all the assets, ground included, are sprites, and all the logic (pathfinding, collisions, etc …) is 2D as well, working on the X/Y axis.
I would be forever in debt of anyone who could solve this with a long term viable solution.
Thanks in advance,
Matt

