How to do this? (destructible terrain inside)

Hey guys,

I’m tying to do a 2.5D Worms clone. Googling around destructible terrain, I found this:

http://motionos.com/terrain/

Now, I’m trying to understand how to implement a thing like that. The author didn’t give out the sources, the only stuff I could find is just a post from the author, where he said:

I’m using the Clipper library (http://www.angusj.com/delphi/clipper.php) and the Triangulator (http://wiki.unity3d.com/index.php/Triangulator) for the terrain. I’m simulating the water with SPH and rendering with marching squares. Ninja rope is a combination of hinge joint and character controller - I’m not really interested in simulating a real rope, I want it to feel like the Worms ninja rope
BTW I just updated the webplayer sample: you can change the brush size, add terrain as well as remove (ctrl+click), and even test out the collider with some particles (right click)

Can someone help me? I’m sure it can be done in 5 minutes, but I’m a newbie in unity so I’d like a small source project with those stuff working. Thanks anyone.

This kind of thing is NOT a 5 minute job. There is some difficulty to it which is why it hasn’t been used much in Unity. From what he described you at least would need to set up a marching squares algorithm which means generating and modifying procedural geometry.

There are numerous approaches to this kind of environment but graphics cards typically don’t lend themselves to doing this easily because they focus more on writing than reading data. You need to be able to read/modify data efficiently and update it and then write it back out efficiently. RenderTextures makes this a lot easier if you have Pro, because then you can just use the GPU to draw air to cut stuff out of a large texture. If the environment size you want isn’t too big ie <=2048x2048 then this is probably the best approach. Otherwise you have to get into some spooling of textures or some kind of dynamic geometry modification/triangulation thingy.

Ok. I had another idea to model the destructible terrain if this way wasn’t praticable.
Well, I was thinking to model the 2D classical terrain of Worms with a “smart” utilizations of the native terrain in Unity. Playing with cameras I can simulate easily a 2D terrain with the native 3D terrain of Unity - right? Tell me if I’m writing strange things.
The heightmap of unity’s terrain should be immediately accessible and moddable via script, right? Can I simulate the deformations provoked by the explosions with this fashion? Just to say, what do you think about it and how would you implement it?

Yes you could view a unity terrain from the side. All you’d need to do is paint the terrain with a 1 pixel-wide strip which represents the cross section you want to show. Then modify it by writing one pixel into the terrain data to modify the height of that pixel. It would give you a solid terrain with no overhangs and no ability to do tunneling or to cut out holes that leave land suspended in the air. So it’s not totally versatile but it would work, and you’d have to figure out how to modify the terrain at runtime.