# How to create destructible terrain using Box2D – step 1

After I showed you various examples of destructible terrain created with Box2D (look here, here and here), it’s time to show you the full tutorial to create destructible terrain.

In this first part I won’t talk about Box2D, I am just showing you how to create a destructible terrain made of polygons.

The principle of the process is divide et impera. Since it would be complicated to manage a polygon with an hole in it, I am going to split a big polygon (the terrain) into a set of small polygons. How small? Small enough the hole made by an explosion can NEVER be completely inside them. This way I will never have real holes in my terrain.

Then it’s easy to use PolygonClipper class to manage polygon breaking.

Here is the script:

And this is the result:

Click to create a hole or drag to dig into the terrain.

• Wow!. Will you implement this in your “where’s my water?” prototype. This’s great… :D

• Christian

n1, i’am excited how you combine this with box2d.
Greets Christian

• That is super awesome!

If I do a “scorched earth”, or “worms” type game, I’m linking to this post ;)

I still recommend every new programmer interested in game development visit your site, so much good info! I’ll just need to convert some of the tutorials to LibGDX some day ;)

• Hi

I’ve managed to create a quiz engine. But i have serious problems with performance late in the game. I have over 100 pictures that the user guesses. Please help me improve the performance of the game. Tell me please what i can do or what to provide. Thx in advance!

• Emanuele dick

It was very nice to rate 1 when I saw that 12 people rated your post 5.
Buahahahaha.

• anlizfer

Hi, is true that Flash is dead for game development? Congratulations from Colombia.

• Nice article :D,

i am gonna try to implement the logic using Haxe :D.

• Pawel

This is great idea and simple implementation. Awaiting for step 2.

• MC

@anlizfer: no, it’s not dead… flash is not longer supported on mobil devices, but the game industry is more than the mobil industry… Flash games are still played (a lot) on desktop and laptop devices

• a guy

Is there any way to translate this code so it works with C++? This is the only tutorial I could find on destructible terrain, but I would like to implement it in a C++ game.