0
\$\begingroup\$

...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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Draco18s Oct 14 '18 at 15:45
  • \$\begingroup\$ It does, actually. As perfect a fix as I could hope for from the limited information I put forth in the post. \$\endgroup\$ – Demetre Saghliani Oct 14 '18 at 16:03
  • \$\begingroup\$ Comment to answer. Glad it worked! \$\endgroup\$ – Draco18s Oct 14 '18 at 16:21
1
\$\begingroup\$

Use a Depth Mask

A Depth Mask shader renders an object only to the depth mask, causing objects rendered after it (and behind it) to be invisible, while objects drawn before the depth mask (on a previous render pass) are visible as normal.

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.

As an example (that I can't access at the moment for pictures) I needed to create a second standard shader that ran before the depth shader (which also ran before the default shader) so that I could layer objects the way I wanted, so that I could create the effect of a pit in a floor without having to remove the floor. Or how Offworld Trading Company does its buildings:

Offworld Markets open for business

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.