# How to make a 2D sprite slowly vanish as it crosses a line — as if disappearing behind a wall?

...Except there is no wall. Only one of its edges.

Here is what I mean. Notice how the lines "sink" into the center square.

I've been trying to do something very similar, in Unity. My approach is to detect when the lines come into contact with the center square (hexagon, in my case), and first initiate an animation that decreases the width of the lines, precisely timed via math to last exactly as long as needed.

But there's a problem. The animation doesn't play. I've spent the last few hours debugging it, to no avail, and now have finally given up, because the problem is too complex to post here. Too many variables.

Are there any better methods of achieving this?

My own, even if it had worked, wouldn't have been perfect, because the width would've decreased on both sides (of the line running in the middle of the thick squares or hexagons that are to disappear), giving it a strange, swallowing effect, but I'd be satisfied, since it's just a practice project.

So, I'm giving up on this approach. What are easier ways to do this? (Preferably in Unity, but I'll take anything.)

Hasty edit: Keep in mind that my "lines" are not sprites but line renderers, but I'm looking for ways to work on either.

• Usually this is done by rendering something in front of the object you want hidden. Note that "something" can in fact be "nothing" ;) That's done by using a Depth Mask Shader: it renders an object only to the depth buffer causing objects rendered after it, but physically behind it, to be invisible (while objects rendered before--using different render passes--and behind are visible). I am unsure if this meets your needs or not, but may help point you in the right direction. – Draco18s Oct 14 '18 at 15:45
• It does, actually. As perfect a fix as I could hope for from the limited information I put forth in the post. – Demetre Saghliani Oct 14 '18 at 16:03
• Comment to answer. Glad it worked! – Draco18s Oct 14 '18 at 16:21

You may have to play around with shaders a bit to get things to render in the right order, but its just a matter of setting their queue in the shader tags; e.g. Tags {"Queue" = "Geometry+10" } or Tags {"Queue" = "Geometry-1" }, etc. Some shaders might expose this value as a configurable property in the inspector. Note that the depth mask shader linked is set to run after Geometry objects, but you might need it to run before, hence the queue number. See subshader tags for more information.