Hi,
I thought I'd ask about this before trying to implement anything, since trying to implement it is maybe quite a lot of work, and I don't know if the results will be efficient enough to be workable anyway... So the responses to this question are likely to influence how my game design comes together.
I want destructable/deformable terrain in my game. The simplest (but least fun and flexible) interpretation of this would be certain static bodies which are flagged with properties in such a way that certain things in the game can destroy them (either by shattering them into smaller bodies or removing them entirely), and certain dynamic bodies could become permanent static fixtures in the level under some circumstances. The more advanced (and perhaps preferable in terms of gameplay) option would be to try to implement a fully deformable environment along the lines of Worms or Lemmings, where pretty much anything can be destroyed or rebuilt on a per-pixel basis, except for certain parts that are flagged as indestructable.
If I were to go about a per-pixel (or per-some-suitably-small-voxel) deformable environment, I guess I'd track it using a texture in the alpha channel of a texture representing the level: Stuff which destroys the environment writes 0 into voxels in the alpha channel of a texture, and stuff which creates bits of environment writes 1. The deformation/creation effects could be implemented quite easily, and the rendering would be pretty straightforward too. I'm not sure how it would translate into collision geometry which Box2D could use, though. Turning each voxel into the texture into a correspondingly-sized static square body would work, but would be pretty inefficient. I guess my approach would be that every time a change was made to the environment, I'd recalculate some kind of quadtree in order to destroy and remake sections of the static geometry to match the texture in such a way that hopefully minimises the number of bodies needed to represent the world.
Does the Lemmings/Worms style deformable terrain sound feasible in Box2D? Is the Quadtree the best approach? As well as the static level geometry, I'm hoping to be able to throw around a reasonable number of dynamic objects as well, so efficient use of the engine is pretty important to me (this is the C++ version, incidentally). Or am I best going back to the drawing board and having most of the environment indestructable, with only specific bodies which can be destroyed?
I thought I'd ask about this before trying to implement anything, since trying to implement it is maybe quite a lot of work, and I don't know if the results will be efficient enough to be workable anyway... So the responses to this question are likely to influence how my game design comes together.
I want destructable/deformable terrain in my game. The simplest (but least fun and flexible) interpretation of this would be certain static bodies which are flagged with properties in such a way that certain things in the game can destroy them (either by shattering them into smaller bodies or removing them entirely), and certain dynamic bodies could become permanent static fixtures in the level under some circumstances. The more advanced (and perhaps preferable in terms of gameplay) option would be to try to implement a fully deformable environment along the lines of Worms or Lemmings, where pretty much anything can be destroyed or rebuilt on a per-pixel basis, except for certain parts that are flagged as indestructable.
If I were to go about a per-pixel (or per-some-suitably-small-voxel) deformable environment, I guess I'd track it using a texture in the alpha channel of a texture representing the level: Stuff which destroys the environment writes 0 into voxels in the alpha channel of a texture, and stuff which creates bits of environment writes 1. The deformation/creation effects could be implemented quite easily, and the rendering would be pretty straightforward too. I'm not sure how it would translate into collision geometry which Box2D could use, though. Turning each voxel into the texture into a correspondingly-sized static square body would work, but would be pretty inefficient. I guess my approach would be that every time a change was made to the environment, I'd recalculate some kind of quadtree in order to destroy and remake sections of the static geometry to match the texture in such a way that hopefully minimises the number of bodies needed to represent the world.
Does the Lemmings/Worms style deformable terrain sound feasible in Box2D? Is the Quadtree the best approach? As well as the static level geometry, I'm hoping to be able to throw around a reasonable number of dynamic objects as well, so efficient use of the engine is pretty important to me (this is the C++ version, incidentally). Or am I best going back to the drawing board and having most of the environment indestructable, with only specific bodies which can be destroyed?