Greetings Lightbringers!
It is Tuesday again, and also time for a new dev blog of Empire of Ember. This week we want to share with you some of the secrets behind one of the coolest features in the game: the destructible physics.
As you know, Empire of Ember allows you to build your own fully destructible city. All cities in the game -including yours- are fully physically modelled, with each brick having its own structural integrity and joint strength, and can come under attack or be attacked by the player and allies under your command.
The destructible physics allow players to plan strategies that use elements of the environment in their favour. For example, catapults can knock out the base of a tower or a wall, which will topple over and crush any units below. Also, the player can blow a hole in the enemies’ wall, leading their army through the breach.
Besides, you can also destroy all kinds of objects. This adds exploration and looting elements to the game, since destroying items drops resources you can use in your own city.

The original concept behind Empire of Ember was that the player would be able to tactically design cities. Kevin wanted the players to consider the actual geometry of how you lay out your walls and towers. Once he had the technology designed to destroy walls, it naturally extended itself to destroying objects in every level. And so it began…
But how does this work exactly? Objects in the game are either tagged as “jointable” or not, which means that they connect together, such as wall segments, gargoyles on walls, or tapestries.
When the level loads, the game simulates physics for about one second to see which jointable objects touch other jointable objects, and how strong of a joint is needed for these objects to connect without breaking. This is more difficult than it sounds, because it sometimes fails between different versions of Unity, or even depends on how fast the player’s computer is, or may even freeze Unity’s physics engine if the scene is too complicated.

Originally, every object in the level was dynamic, meaning it could move at any time. This means a tall tower would sway in the wind, for example. However, with hundreds of wall sections, this takes a toll on the game’s physics engine performance. As a compromise, all objects start kinematic, which makes them high performance and stable. They change to dynamic when they take damage or if being kinematic would cause them to float in the air.

There is a small trick, as not every single object is destructible in the game. In the solo ‘suicide’ missions, for instance, some large objects -such as buildings- are not destructible. The reason behind this is that they serve for occlusion culling, thus limiting how far the player can see and helping with the frame rate.
Implementing destructible physics in the game has also brought a few technical challenges. Fully destructible dynamic content requires a lot of processing power, much more than people who are not into game development might have available on their computers.
For example, placed lights can use lightmapping at build times so the math used to determine how those lights look was already calculated on the developer’s computer. Dynamic lights, including lights that shine on objects that might move or be destroyed, have to be calculated every frame while the game is running. You can clearly see the difference in the tutorial versus our other levels. The tutorial was pre-designed so we are able to use every optimization trick which we cannot otherwise normally do.

Frame rate is also more difficult to optimize having destructible physics. Some players keep asking why they cannot get 100 FPS in Empire of Ember when they can run other games like Cyberpunk or The Witcher at this rate… Well, the answer is simple: these games have static environments ;)
Optimizing the game has been a lengthy process. When the combat was first introduced two years ago you could only have 20 enemies fighting at a time, without the player present, on a map that was only a flat plane at 30 FPS. With today’s optimized code, thanks to caching and time-slicing, most levels should not drop below 60 FPS. Even in the worst-case scenario with 100 enemies at a time and full physics, you shouldn’t drop below 30 FPS. This has been possible thanks to many months of working on game optimization.

And this is all about the destructible features for now! Before we go, we would like to invite you as usual to join our community on Discord, the Steam forum, and follow us on Twitter, Facebook and Reddit. Please wishlist and follow the game, and tell your friends about it!
Stay safe and have a great week!
