This tutorial is not intended for beginners. If you are just starting to learn Chaos Destruction, you should first study all the tutorials from Epic Games and the community, and then move on to this tutorial.
Hi, everybody.
There are very few really valuable tutorials on Chaos Destruction on the internet. I think I’ve explored all of them, including the official ones from Epic, which provide only basic and generalized information for all projects.
I spent a lot of time learning Chaos Destruction and decided to create a little tutorial with tricks and tips for creating realistic destruction.
This particularly touches on creating destructible buildings with proper collision, since Chaos Destruction we should mostly use convex collision for best performance.
I really liked the destructibility in The Finals game and was trying to figure out how they made destructible buildings with proper collision.
First of all, I will talk about the problems I encountered when creating destructible buildings.
So, let’s say we have a wall of a building that we can get inside.
We have divided the wall of the building into fragments that must be destroyed.
But as I said earlier, Geometry Collection will automatically create a convex collision and in this case the collision will overlap the through holes that should be open.
I’m creating a 1st person shooter, so it’s crucial for my game that all collisions work with exceptional accuracy.
Therefore, it is necessary to use a slightly different method of creating fragments for walls.
One working method would be to create fragments from blocks (voxels, bricks). This may allow for a quick solution, as you can size the blocks so that one block does not overlap the corner of the through hole.
Or at least it won’t be as critical as in the case above.
But in that case we have 3 new problems:
-
Destructibility will not look so realistic compared to voronoi algorithm, because all objects will be broken into blocks. For example if we have a house made of wood, it will look weird.
-
There can be too many blocks and this can have a negative impact on performance as each block requires physics miscalculations at the moment of destruction. This needs to be tested in practice though, as the blocks may have a simpler collision (boxing) when doing so.
-
The most serious drawback specifically in my case, namely for an online game, is the replication of a huge number of fragments at the moment of destruction. This can destroy the network.
Thus I propose another option for creating destructible buildings.
First we have to “cut” all the corners of the through holes.
We have to do this in fully manual mode using the Planar tool in Fracture Mode.
We should end up with roughly this result.
You can actually slice in a variety of ways, including slicing at a 45 degree angle.
This is left to your discretion.
The basic rule is to try not to get more slices than the minimum required.
And then we can apply any fracture algorithm. In my case it will be voronoi.
Now the through holes will not be overlapped by collision.
The next problem I encountered had to do with the collision of building corners.
So, let’s imagine that we have a corner of a building.
Using the voronoi algorithm, we divide the corner of the building into fragments and get roughly this result:
As we already know, Geometry Collection will automatically create a convex collision that wraps the fragment along the top edges. In this case, the collision will be completely broken and the character will simply not be able to approach that corner.
Also, when that fragment is broken, it will interfere with shots through the corner of the fragment.
Once again, 2 solutions come to our rescue:
-
Fracture using blocks (bricks, blocks). This will fix the problem, but introduces the additional problems mentioned above.
-
Using our favorite Planar, with which we also slice our building at the corners.
After that we can apply any other fracture algorithm and get a working result with correct collisions.
So, now we know how to properly slice an object into slices.
Now we will build a complete building using the tips described above.
Also following Epic’s advice, we will add an anchor field to anchor the building in place as if it were a foundation. Otherwise, any physical impact on the house might just move the house, which would look weird.
In the end we should end up with roughly this result:
Now let’s switch to game mode and try to destroy our building.
And at the end you will notice a new problem: the whole building will be held up by a small wall or column. It looks super unrealistic.
Let’s get to fixing the problem.
First, let’s take a look at the links that were automatically built by Geometry Collection.
For this purpose we can use 2 console commands:
p.Chaos.DebugDraw.Enabled 1
p.Chaos.Solver.DebugDraw.Cluster.Constraints 1
You can see the blue dot near the very bottom of the fragment. This is the anchor point that holds the building together.
So, as long as all the anchor points do not lose their connection to the rest of the building, then the building will be stable.
Of course, this can be used to advantage for some scenarios, but specifically in our case it looks bad.
There are a few possible fixes.
The first solution is to use the dynamic (or sleeping) state of the object. But here we get new problems:
-
As mentioned above, any physical impact can move the building.
-
If the player successfully destroys some fragments (e.g. with explosives) that create the main physical support for the building, the building will simply collapse.
To solve this problem, we will perform some manipulations.
First we need to create a new Actor, where we will put our GeometryCollection.
After that, let’s add some anchor actors for supporting areas of the building. In my example, these will be the corners of the building.
Don’t forget to add these anchors for the GC. This can be done through the Construction Script.
Then we need to add some Master Field for our building. This is necessary to partially destroy the building at the moment of damage to the support.
In my case there will be 4 Master Fields on each corner.
Let’s assign each anchor its Master Field. This will be useful for us in the future.
Next, we need to customize our Master Fields a bit:
-
Activation Type → Trigger;
-
Field Falloff Shape → Box;
-
Disable: Use Radial Vector, Use Direction Vector, Use Torque, Use Noise;
-
Enable: Force Dynamic Switch;
Now we need to be notified when fragments are destroyed.
To do this, activate “Notify Breaks” for Geometry Collection, and add “On Chaos Break Event” node from Geometry Collection.
When we receive a break event, we get the position of the fragment from the event structure.
We can check if this fragment is inside the anchor field using the anchor area.
If the fragment is inside the anchor field, then it is our bearing wall. In that case, activate the child Master Field inside this anchor.
This will cause the building to partially collapse.
You can easily experiment with this.
For example, you might want to collapse only the first floor of a building, while the second floor should remain intact. It depends on your requirements.
Here you can take a look at my example of breaking a complex building into fragments.