Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
3  
    
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? –  bummzack Jun 6 '13 at 14:51
    
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. –  BrotherJack Jun 8 '13 at 1:52
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.