6

I wrote a processing sketch that generates hills for a scorched earth clone, like this:

enter image description here

I'm trying to figure out how to make this a physics object in libgdx, but I'm having problems figuring out how to do that.

I thinking about doing this through a ChainShape composed of a vector2 array at each point on the slope. I've tried running this on an android device through a Box2DDebugRenderer and SpriteBatch, but I can't get anything to show up (although that's another problem).

Does anyone know how to make a physics object like this in box2d?

House
  • 73,224
  • 17
  • 184
  • 273
BrotherJack
  • 269
  • 4
  • 10

1 Answers1

3

From the documentation on the Box2D site:

Worms Clones

Making a worms clone requires arbitrarily destructible terrain. This is beyond the scope of Box2D, so you will have to figure out how to do this on your own.

So you're on your own for building a new terrain when the old one gets a large crater blown into it. I think, following the questions I linked in my comment (How can I generate Worms-style terrain? and How can I convert a 2D bitmap (Used for terrain) to a 2D polygon mesh for collision?), you'll be able to create the terrain and then create a custom polygon shape. The shapes must be convex, so you'll have to break the terrain into smaller convex shapes if the other all shape includes concave portions (like craters, tunnels, etc.).

There's a tutorial here that shows the creation of these shapes. Essentially, you're creating a polygon using a definition object, then passing that definition into m_world.CreateBody(...).

House
  • 73,224
  • 17
  • 184
  • 273