6
\$\begingroup\$

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?

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Combine how-can-i-generate-worms-style-terrain with how-can-i-convert-a-2d-bitmap-used-for-terrain-to-a-2d-polygon-mesh-for-collision. \$\endgroup\$
    – House
    Commented Jun 6, 2013 at 13:42
  • \$\begingroup\$ Using a ChainShape looks like the correct approach to me (should be easy with a landscape as in your image). What doesn't work with that approach? \$\endgroup\$
    – bummzack
    Commented Jun 6, 2013 at 14:51
  • \$\begingroup\$ From what I can tell it does work, and it doesn't seem to be terribly inefficient (I'm not noticing any crippling slowdowns anyway). I just had some problems with implementing the Debug Renderer camera. Whether this is an effective way to generate terrain is something I'm not 100% on. \$\endgroup\$ Commented Jun 8, 2013 at 1:52

1 Answer 1

3
\$\begingroup\$

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(...).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .