- Home /
Implementing destructible terrain, deformable ground, or craters for an artillery game (think scorched earth!)
Hi, I'm fairly new to Unity3d and was wondering how to go about implementing a boolean operation on a mesh equal to the radius of an explosion, or any equivalent effect to achieve a hole in the ground. This is an important element within artillery games. I have a feeling it will be non-trivial, but any help or a point in the right direction would be greatly appreciated. I am using an imported mesh, but I can switch to terrain if it would be easier to implement.
The relevant questions I found suggested moving each vertex within the explosion radius outward, but I'm lost on how to do this. I found http://unity3d.com/support/documentation/ScriptReference/Mesh.html , which is a good starting point, but I need a push in the right direction from here!
Answer by duck · Sep 28, 2010 at 08:27 PM
Because the terrain system uses a heightmap instead of regular mesh data, you can't modify the vertex positions directly.
Instead you have to adjust the values stored in the heightmap using GetHeights and SetHeights.
For a crater, you'd want to reduce the heights of the area nearest the explosion, but raise the heights around the crater's lip. You'd probably also want to modify the texture used at that position on the terrain.
These separate techniques have been described in other answers on this site, so follow these links for more information:
Thank you, I'll try this technique and report back if I have any troubles!
the links you have mentioned arnt working anymore ... :\
Answer by FilipBaba · Mar 28, 2012 at 08:48 PM
These features of Unity have very little documentation. It took me allot of digging around and experimenting to make a practical deformable terrain. The concept is that Unity terrain stores Height data in a 2 dimensional array [x,y] the height is a float from 0.0 to 1.0 and it can be changed at runtime. To give craters a round concave look we use a texture with an alpha map. We then convert the pixel data from the alpha map into a float ranging from 0.0 to 1.0 depending on how dark the pixel is. Then all that is left is to subtract the crater Height Data from the Terrain Height Data at the impact Vector3 position.
For the textures the process is very similar but it differs in the following way: For every texture you have on your terrain (In this case 2 textures: Grass and Dirt) you must adjust it's alpha value, for example: To get dirt we must make: Grass alpha = 0.0 Dirt alpha = 1.0 to blend grass and dirt we must make: Grass alpha = 0.5 Dirt alpha = 0.5
You can find my implementation here: http://www.youtube.com/watch?v=2W3Vm1_QGf0
Your answer
Follow this Question
Related Questions
Modify a mesh at runtime 0 Answers
Get Terrain location at raycast point 1 Answer
How to make trees in a terrain transparent in runtime? 0 Answers
Paint Terrain Texture From Vector3 List 0 Answers
lowering Terrain at run-time, C# 0 Answers