Creating a hole

I want to create a hole in a plane mesh.

I’ve uploaded a screenshot to explain better.

On the screenshot there is a mesh shaped like a square but only the borders. I want the plane part inside the borders to be invisible, so that it looks like a hole, kind of like a pit.

The ground is a plane object.

How can I achieve this?

Thanks for your time

Do you want the mesh to actually be deformed (i.e. verts/edges/faces get changed) or just the texture to not be visible inside the “hole” but the original plane remains intact (is the mesh also being used as a collider? do you want things to “fall in” the hole?)?

my “mesh-fu” is very lacking to answer the question itself, but I would imagine the first would involve scripting to alter the mesh, but the later might just involve some “shader-voodoo”.

I just need to hide the plane part that is inside that hole, the basic idea is to make a turret come from deep that hole to the surface when a player builds a turret on that “Building Zone”(the square)

If you’re not going to fake it with textures (this is what a lot of games do) then you’re in the realm of performing boolean operations on the mesh. There’s some assets that do this, see here: Boolean Subtraction Operations on Mesh - Unity Engine - Unity Discussions

I might tackle this with the stencil buffer. See here for a good introduction.

I think that won’t be a very good choice, I’ve downloaded “Boolean Ops” and it says there on the readme:

while I will need this action of making the hole transparent many times :frowning:

You could do this without modifying the mesh by using a depth mask:
http://wiki.unity3d.com/index.php?title=DepthMask

1 Like

Do you know how I could implement this? I’m a total noob when it comes to shaders… if you have time ofcourse :slight_smile:

Did you try? The shader code is literally in the link.

I downloaded the package included in the link and applied the shader to a material, then the material to the mesh and the mesh just disapeared… so I have no clue what went wrong

The mesh uppon which you applied this shader would be your depth mask, your hole if you want. So it is normal that it is not visible. Move it such that it intersects with other meshes and you should observe a carving effect.

So, I applyed SetRenderQueue script to my ground plane, and set the Queue to 3020 like it says in the link.
Then created a new plane and applyed the material to it.

But nothing seems to change :s

EDIT: I tryed doing the same but instead of using a plane using a unity 3d Cube and it works!

Thanks everyone for your time and help :smile: