Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

How would I cut a hole in a terrain for an underground scene

Discussion in 'Editor & General Support' started by StreetwizeSB, Mar 31, 2010.

  1. StreetwizeSB

    StreetwizeSB

    Joined:
    Mar 6, 2010
    Posts:
    5
    How would I cut a hole in a terrain for an underground scene?
    not sure this is the right place for this question, but I didnt see any other forum where it would go either.
     
  2. StreetwizeSB

    StreetwizeSB

    Joined:
    Mar 6, 2010
    Posts:
    5
    So far what i have done is raise the terrain up then cut trenchs through the terrain then build meshes in other programs to drop on top of the trenchs but its getting old. i would rather cut a hole in the side of a mountain and drop a tube there with a bunch of tunnels going here and there.
     
  3. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    In general: not possible the way you want it. Sorry

    Your idea is one possible solution.

    The other idea would be to create some kind of cave entrance and load another level upon entering.

    The third potion would be something like this probably:
    http://forum.unity3d.com/viewtopic.php?t=8354&highlight=hole+terrain


    Sorry that I can't tell you more. It's been asked quite a few times already and there are also quite a few threads about it. I never had to deal with this personally, though. So I can only offer so much help...
     
  4. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
  5. jackpile

    jackpile

    Joined:
    Apr 13, 2011
    Posts:
    27
    Wow, long-time issue I see. I have the very same problem right now. A simple (obvious?) solution is to deactivate the terrain before entering a cave entrance and applying non-terrain assets/meshes prior to the opening to disguise the fact that the terrain has been pulled out from under you. It's a hack for sure, but sometimes hacks are 100x easier than doing the kosher thing. :) Sure, you could use a different scene to avoid that or you could painstakingly design your own terrain mesh in Maya or what have you, but when you've already spent months designing a game architecture where one scene == one level, it's not so easy. Hope this helps someone in the future. Cheers.
     
  6. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Actually I'm about to implement caves in terrain myself. My take on it was using two camera's, and then render a hole on top of the terrain.

    There is a Portal Demo that uses this technique in this forum thread: http://forum.unity3d.com/threads/2296-Portal

    Its based on a custom shader that renders transparency on top of the terrain and then seeing cave through that hole with the other camera that. (The other camera is configured so it doesn't render the landscape layer and the first so it doesn't render the underground stuff.

    Cheers,
    UnLogick
     
  7. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Turned out being quite easy.... Right here its not pixel perfect aligned with the terrain, its simply a plane that I aligned manually. The cave Camera should have a lower depth than the terrain camera. This is a basic feature and the performance impact is quite low. Don't know what the overhead of adding an extra camera is, but the only part that requires multiple passes are the actual opening where we draw both terrain and the transparency filter and gets nothing to show for it.

    It worked out pretty well... can't wait to see the cave models that our artists will produce. :D

    Edit: Now if someone could tell me how to disable terrain collision for just this opening that would be nice. Do I really have to make a custom collision mesh near these openings?

    Cheers,
    UnLogick
     

    Attached Files:

    Last edited: Feb 12, 2012
  8. Statement

    Statement

    Joined:
    Oct 18, 2010
    Posts:
    18
    If you make a custom collider for the patch, and use a trigger to sense when objects get inside a safe distance, you can probably ignore collision between the object and the terrain until the object exit the trigger.
     
  9. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I know this isn't rocket science, but in my case the users are digging their own tunnels, so this can happen on terrain boundaries as well. This could potentially involve four terrain patches where terrain collision needs to be ignored for objects within this particular trigger (and only those). Not to mention that players could dig and such alter the meshes real time.

    But I'm unlikely to find a better solution than to make my own collision mesh, its not much different from the mesh I need to overlay the terrain where the hole is so I better stop whining. ;)
     
  10. KingShizel

    KingShizel

    Joined:
    Oct 29, 2012
    Posts:
    17
    Wait wait wait wait wait. Okay i look up portaling in unity and i get Portal... the game. So i quit the idea after an admin told me to look into it. Now your tell me that i can.... Can someone explain to me how to do this. i would really love it. So far i have been turning the terrain into a mesh in a different program and reporting it over and before i do all that, just for testing im using alpha masking. So can someone explain this please!?
     
  11. BolderBoy

    BolderBoy

    Joined:
    Oct 14, 2014
    Posts:
    3
    I was looking into the same problem. What I came up with is to apply a transparency to the terrain.

    http://wiki.unity3d.com/index.php/TerrainTransparency

    Apply a spot of transparency to the "hole" in your terrain; this way the user will not be able to see the terrain mesh. The collider will still be on though so you will need a cave entrance model to make the transition. When the user enters your cave entrance a collision box is used to detect the player and toggle the terrain collider on or off accordingly.
     
  12. BolderBoy

    BolderBoy

    Joined:
    Oct 14, 2014
    Posts:
    3
    Or you could convert the chunk into a mesh then remove the desired geometry using Boolean Subtraction.

    http://forum.unity3d.com/threads/boolean-subtraction-operations-on-mesh.85713/

    Manipulating the collision seems like it would work as well. However then you may run into bugs where other objects either do or do not collide with the mesh.

    To get around this any object that passes through your collision box regulating the entrance to your cave needs to be processed differently than usual. Also this special processing must only apply to the object passing through / sitting in the collision box. Otherwise shooting a missile through your cave entrance might drop the player character through the world. Just a couple things to consider.
     
    Last edited: Apr 13, 2015
    MagicStyle likes this.
  13. Paulieknewport8838

    Paulieknewport8838

    Joined:
    Jun 4, 2017
    Posts:
    1
    im looking for a workthru here and i really like the idea of converting the terrain to a mesh. but i think making a dummy placeholder mesh and then using it as the terrains collider would be nicer. more lines of code. alot of good ideas here ill be back when my terrain is done to share. however.. converting the entire thing to a mesh would allow for removal of the triangles used in the hole. i may just write a script that deletes faces from a mesh and convert my terrains over.