After uploading the super hero game I made a page for, I wanted to revisit the idea and implement a different way to ‘destroy’ the buildings.
In the original code, once a wall was hit by either a projectile or beam (or a fast moving player), it would remove the original wall, and ‘fill in’ that wall with equal sized cubes, and if a damage threshold has been reached, it would apply physics to those cubes in the effected area, and then an explosion force to the cubes.
As you can imagine, for large walls it was extremely inefficient to remove the entire wall and replace the whole thing with smaller cubes. The cube size I was using was 0.5m x 0.5m x 0.5m. So a single wall that was 100 meters high and 100 meters wide (with only a depth of 0.5m) is 10,000 cubes. And each cube has 6 faces for 12 triangles (2 triangles per face); it starts to very quickly become very expensive in terms of processing power. Especially if the player was only hitting a very small part of the wall.
In the latest update I’ve been working on, I changed the way the code works so that I’m actually manipulating the vertices of the cubes, and generating new cubes on the fly. Essentially, when a wall is hit I have the code split the wall in half lengthwise, then heightwise, and continue down splitting the wall in the area that is affected. So instead of replacing the entire wall, I end up only replacing the effected part, and the rest of the wall is more efficiently split apart.
I’m debating on posting all the code for the game once I clean it up a little more, or possibly going through it and adding multiplayer support.