x


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!

more ▼

asked Sep 28 '10 at 07:06 PM

nathaniel gravatar image

nathaniel
27 3 3 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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:

Modifying terrain height under a gameobject at runtime

Modifying Terrain Splat Texture at Runtime

more ▼

answered Sep 28 '10 at 08:27 PM

duck gravatar image

duck ♦♦
40.9k 92 148 415

Thank you, I'll try this technique and report back if I have any troubles!

Sep 28 '10 at 08:42 PM nathaniel
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Mar 28 '12 at 08:48 PM

FilipBaba gravatar image

FilipBaba
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1464
x374
x38
x32
x15

asked: Sep 28 '10 at 07:06 PM

Seen: 3640 times

Last Updated: Mar 28 '12 at 08:48 PM