Search code examples
unity-game-enginesprite

Hiding a sprite behind a wall, but showing when its in front of the wall, Unity


So I have been working on this little project, and I ran into a problem that I would like to fix before I continue. I have a wall that's part of the tile map, and I need to hide the characters obstructed by the wall, when they are behind the wall, without hiding them at all when they're in front of the wall. If I set the order in layer of the sprite lower than the layer of the wall, then it will look right when the sprite is behind the wall, but not correct if the sprite is in front of the wall. If the order is the same or higher than the wall, then the opposite is true, looks fine in front, doesn't work behind. To show exactly what I mean:

When the sprites order in layer is set lower than the wall enter image description here when the sprites order in layer is set to the same or higher than the wall enter image description here

I know of a few potential solutions, but the solutions in mind are not very good for reasons of complexity/difficulty. Like many of my problems here, I suspect theres an easier way, but also like many of my problems here, I dont know enough about unity to be aware of it. Ive searched around the unity documentation, but im not really sure what is applicable to my situation. Any pointers?


Solution

  • figured it out. The wall and sprite need to be on the same order in layer, then go to Project settings > graphics > transparency sort mode: custom axis > x 0, y 1, z 0. Then go to the wall in the tilemap, in the tilemap renderer component, set the mode to individual.