Destructible walls! (and maybe other stuff?)


Hello again!

I am back to write words again.

Today we're gonna gloss over the wall destruction tech that I'm still writing for this game demo.


Here's some holes that got shot out of the wall and the accompanying ordinary bullet decals and some loose bricks that went flying in the process. (The ordinary decals btw are just normal quads being rendered in front of the wall. They have a shader that will fade them when depth becomes too great "behind it", making it appear to cut off outside edges. They're not really "real" decals as I'd like them, it's just too big a hassle to implement deferred decals in Unity standard rendering pipeline. I'm sure it's much easier in HDRP but I don't do that stuff yet.)

So what is this really? If your first guess is that the wall is a grid of smaller objects you're only half-right.

I modify the mesh real time to cut holes. But I don't cut arbitrarily shaped holes like these. I cut a very simple shape. A quad!

But there's no need to do any math to actually cut that piece out, just remove some of the vertex indices so that triangles form into nothing (and preferably clean up the degenerate triangles that are left hanging), effectively making a hole in the wall, with only modification done to the mesh data as it is, no math included! (well, some math but not a lot)

The reason why I don't wanna do this math intensive is of course because we're going to be doing a lot of it. And so far, the frame rate holds up pretty well even with dozens of enemies and stuff shooting up walls left and right.

The heaviest math involved is probably the generation of the UV-coordinates for the bullet holes and the wall in order to get them to match up seamlessly. The wall only needs to calculate them once but the bullet holes are a need-to basis. When they appear, they're gonna need to have UV-coordinates that are appropriate for their location in relation to the wall.


Another pic where I shot across these three walls, to show the still pretty variable location and look of the holes.

And so, of course, since we're cutting the mesh. The holes are physically see-through.


(The green tube is the player heyoo)

But! We can't shoot through them right now. I've opted to implement bullet pass-through to emulate it instead, the holes just kind of look cool.

And of course, once a wall takes enough damage from high-powered weapons or the player (or a specific enemy rushes through it) we make the wall pop.


Now this is the same broken mesh over and over, that's of course going to be fixed to add variation to it. I'm actually thinking of making the pillars that separate the walls be destructible as well so that walls really would get decimated in heavy gunfire.

But a big part why this was implemented at all is because we will have a city portion in the level, and we just need to have entire building facades chewed through!


There's a lot of additional stuff one could add with proper decal support. You could add scorch/flash marks and parallax mapped bullet holes to complement the physical holes even further, but we'll see how far I can take it. We need to constantly keep track of performance.

And speaking of that, I want to make another post about this. There's a lot more to cover in ways of performance, how to manage it and the closer look at the physical makeup of these wall assets and how I dodged doing a lot of math just by having a nights rest. Cliffhanger! :D

Bye!

Get "P4" (Untitled game)

Leave a comment

Log in with itch.io to leave a comment.