Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Creating a hole

Discussion in 'Scripting' started by Morseton, Jun 8, 2016.

  1. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    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
     

    Attached Files:

  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    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".
     
    Last edited: Jun 8, 2016
  3. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    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)
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    I might tackle this with the stencil buffer. See here for a good introduction.
     
  6. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    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 :(
     
  7. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    JoeStrout likes this.
  8. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    Do you know how I could implement this? I'm a total noob when it comes to shaders.. if you have time ofcourse :)
     
  9. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Did you try? The shader code is literally in the link.
     
  10. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    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
     
  11. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    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.
     
  12. Morseton

    Morseton

    Joined:
    Jan 15, 2016
    Posts:
    90
    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 :D