In search of fast and beautiful terrain destruction
Hello! I am Niels Uiterwijk, a game programmer working at Codeglue, a small indie company in Rotterdam, the Netherlands. I am currently working as the tech lead on a game called Antegods.
So, what is Antegods?
Antegods is our action-packed arena game in which the remnants of the Mayan civilization have taken to space. Two teams of 4 players each control customizable stonepunk mechs to hunt for energy and fight off opponents in a procedurally generated and highly destructible map. The ultimate goal is to activate enormous ‘titan’ statues that will bring explosive mayhem down upon the enemy team.
We’ve been working on Antegods for over a year now and I would like to share some of the more interesting development challenges we’ve faced so far. The first thing I would like to talk about is the destructible terrain in the game! Antegods is the spiritual successor to our game Rocket Riot, which has a really cool feature; everything is made out of 3D pixels and can be destroyed, but all pixels will grow back! Nowadays this is a less unique feature as we are used to games such as Minecraft, and so felt we had to bring destruction in our new game Antegods to another level.
So about two and half years ago, before we started working fulltime on Antegods, we asked an old intern and friend of ours, Tobias Wehrum to do some prototyping on this idea we had for a new type of terrain destruction. We didn’t want those 3D pixels anymore, but we wanted to destroy complete 3D meshes this time. You can see Tobias’ early work in the image above.
Since Tobias' first prototype the game has come a long way. In the image below you can see the same technology working in one of the latest versions of Antegods.
One of the biggest challenges was to make sure the destructible terrain doesn't have too much of a performance hit on the game. You can easily disable graphics settings, but you can't disable a core feature of the game! We first tried breaking the terrain real-time, but that proved to be very costly. So the way it works now is that we pre-slice the destructible 3D models into smaller 3D models. This is done before we load a level. How fine-grained we slice the blocks is configurable, so we can have different types of blocks breaking into larger or smaller chunks. We use this to visually differentiate the various types of blocks we have: some types of blocks are really hard and break in smaller chunks, while some are more brittle and break into larger pieces.
One of the constraints at the moment is that the system is designed for slicing rectangular shaped objects only. They don't have to be completely rectangular, but they can't differ too much either. However, for future versions of Antegods we want to be able to slice 3D objects of all kinds of shapes. You can think of Mayan temples and more naturally shaped rocks for our terrain.
So how do we do it?
Our terrain blocks are usually rendered as a single mesh, but as soon as they get destroyed by a projectile or a game character we quickly hide it and start rendering the individual pre-sliced meshes. This allows us to have many destructible blocks in the scene, while limiting the amount of draw calls. In the image below we disabled the rendering of the original static mesh. You can see that as soon a player dashes through the blocks (this feels very good btw!), the individual pre-sliced meshes appear.
One effect that many people seem to like is when the terrain grows back. Specifically that it grows from the inside out, so it looks like the terrain is patching itself up again. We achieve this effect by storing all information from ‘explosions’ in a list, and afterwards having the explosions slowly shrink again. As you can see in the image below the red sphere shows the size of the explosion and the terrain growing back when the sphere shrinks back to zero.
The explosion keeps a tally of all the (temporarily invisible) blocks it affected and when shrinking it will check if such a block is still within its radius. Once the radius is sufficiently small or no more blocks are affected, the explosion is removed and the original single-mesh block is made visible again.
Well, that was my brief preview of the destructible terrain in Antegods. Our next post will be about how we have solved the procedural level generation in our game. We also frequently post about the development of our game on our own blog so keep an eye on that for more tips and tricks. And don't be afraid to let us know what you think! We actually like that.
Finally, we are running a crowdfunding campaign on Fig.co at the moment and we would love it, if you can help us spread the word. Thank you!