- Home /
How to make holes in your mesh/terrain during runtime?
I have researched and I've seen you can do some shader+collision tricks to make holes in terrain. So for a flat terrain, using a simple plane with the special shader would work to make a hole. So it seems you would need a preset mesh to overlap onto your mesh that you're trying to make a hole in.
However, lets say you have a custom terrain mesh and you want to dynamically create round holes onto the ground. What would be the best way to approach this?
Should I find a way to only select and duplicate the specific polygons somehow 'cut it out into a circle or whatever shape I wanted and take that mesh and apply the masking shader? Even though that wouldn't quite make sense since it's probably not possible to do that, or we wouldn't even need the special shader, if we can cut out shapes in the mesh?
Is it possible to overlap to mesh objects? and somehow cut out the intersecting?
Any guidance in this matter would be most helpful.
Thank you in advance!
Edit:
To clarify my question, I definitely mean during runtime/gameplay. In this game theres a type of digging action, and you'd be able to choose whatever location on the terrain. So pre-making meshes to make holes would not be an option.
Answer by Fattie · Mar 25, 2013 at 10:37 AM
"Is it possible to overlap to mesh objects? and somehow cut out the intersecting?"
You would have to do this BY HAND, working with the mesh. This is by no means simple, and not something you can do as a beginner.
Now, is there an existing tool that does this? I'm pretty sure, no, I've not seen any tool (say on the asset store) that will take a flat mesh, a "ground", and knock a hole in it.
based on your further comments ...
Note that using a PROJECTOR is a very common and very simple solution to what you are describing.
(A "decal" is somewhat similar conceptually, but it does not work if the ground is, as you say, not perfectly flat. A "projector" will work perfectly for you here -- depending on the look you want.)
To try a projector basically, just click once to add an example projector ("blob light" or whatever) from the standard example assets
I am trying to make holes in terrain meshes by runtime. I have already been able to make 'visual/rendering holes' by applying shaders to certain objects. $$anonymous$$y problem is that my terrain is hilly/bumpy. So let's say I apply the special shader to a plane, and put it on the ground. It would make a visual hole on the terrain. But only where the plane actually is placed. And since it's not shaped into the bumpiness of the terrain. We'd have a weird visual hole.
Thanks for your reply it sounds very promising so far. Once I get back to my computer, I'll look into that and check answered if it seems like the correct road to go down.
Answer by Venryx · May 13, 2013 at 08:44 PM
Tarlius' response is in the right direction. That will take care of dynamic terrain texture changes.
To actually make holes, though, you have to have a texture that it switches to, that's transparent, and a script system that makes objects fall through those dynamically-made-transparent areas.
I've made a plugin for this second half, that can be found on the Asset Store: Terrain Hole System
Description: "This Unity extension lets you make holes in your terrain that characters and other objects can go through."
More information can be found on the forum thread.
To get it working with the dynamic texture setting, just have the dynamic-texture-setting set the terrain texture of the area to the "Transparent" texture talked about in my plugin's manual.
Let me know if you need more details into how to get this to work.
Answer by Tarlius · Mar 25, 2013 at 11:11 AM
I would suggest looking for "destructible terrain".
Check this out. I didn't read the code, but the concept is explained in the video description. Basically he uses a texture to adjust the hieghtmap. The disadvantage of this is there will be no way to make "caves", which might be a problem.
voxelform looks like it would get around this (and looks awesome in general), although I can't find it on the asset store now. :(
If you aren't looking to do this in real time, then Fattie has the answer
(Disclaimer: I am not affiliated in any way with either of these solutions)
Thanks for you answer.
Voxelform looks to be the most promising solution so far, I do need actual holes in terrain, ins$$anonymous$$d of heightmap changes. Though, I have no idea what the cost is yet. I'll have to research it further.
Edit:
After searching around, Voxelform seems to be a dead plug-in to be found nowhere. Perhaps...I'll have to figure out how it was done and duplicate the process.
writing a voxel engine is a staggeringly large undertaking. it is inconceivable you could do that, purely to solve the problem at hand!
yes, voxelform.com disappeared mysteriously about a year ago. it was a vaguely $$anonymous$$ecraft-like technology.
Your answer
Follow this Question
Related Questions
terrain hole shader needs fixing 1 Answer
Lighting Banding Artifact 0 Answers
Questions about render distance in an open world game 0 Answers