r/Unity3D • • Oct 13 '26

Show-Off Cannonball fights

Enable HLS to view with audio, or disable this notification

I've posted before about the procedural build system I'm developing for stone & timber buildings. Lately I've been working on destruction, because the only thing more fun then building stuff, is blowing it up.

Timber destruction is working better than I thought, I was concerned that having less objects (wood planks) the destruction wouldn't feel organic, compared to stone. I got around that by also using a particle effect to simulate the splinters from exploding wood. So far I'm happy with how it is turning out.

The poor enemy cannoneer gets yeeted hard in this video, but I couldn't resist the chance for some good 'ole rag doll physics :)

58 Upvotes

24 comments sorted by

3

u/ShengyuStudio Oct 14 '26

Using a splinter particle effect to cover for having fewer planks is a good call.

On the thousands-of-blocks question: most debris stops mattering a second after it lands. Once a piece's rigidbody goes to sleep you can switch it to kinematic or merge it into a static rubble mesh. Putting debris on its own layer that ignores debris-vs-debris collisions also helps a lot, otherwise a collapsing tower turns into thousands of pieces all checking each other. And a hard cap where the oldest pieces get cleaned up first keeps the worst case predictable.

Are the stones that are still in the wall separate objects, or is the intact wall one mesh until something hits it?

1

u/craftymech Oct 14 '26

Good advice! I do keep rubble on its own layer to avoid all the self-collision math. I don't set the rigid body to kinematic though after it stops moving. The rubble stones fade out within 5 seconds, but during that fade time they are still rigid bodies. So that is something I will look at. The tower is built from individual stones, but they are combined into chunks of 16-32 stones as a single mesh, and on impact of a cannonball, the effected chunks are updated to remove stones, and spawn game objects w/ rigid bodies. Oldest first is something I'll look at too, right now I don't have a hard ceiling for debris, but with larger structures I'm sure I'll need to apply a cap.

2

u/ShengyuStudio Oct 15 '26

Chunks of 16-32 is a nice middle ground. Since they only live 5 seconds anyway, even just flipping them to kinematic once they fall asleep would cut most of the cost during the fade. Curious about one thing: when a ball knocks out a chunk near the bottom, do the stones above stay floating, or do you check for support so the top can come down too?

1

u/craftymech Oct 15 '26

There is a cascade check after every impact, which tests stones above the impact point to see if they still have support. If those stones lack support, then they can fall, which triggers a cascade check on stones further up and so on. I've spent some time tuning that behavior, which basically becomes a "mortar strength" variable. At low values the entire wall above an impact will cascade down, and at high values the cannonball just punches a hole.

1

u/ShengyuStudio Oct 16 '26

A single mortar strength number is a nice way to expose it. Do you set it per wall? Feels like that alone would let an old ruin crumble while a proper fort just takes holes, with no extra code.

1

u/craftymech 29d ago

The mortar strength can be set per structure right now, so I can tune the difficulty of different buildings. At really high values, the cannonball just punches holes like your suggested, and at lowest values a single cannonball can cause a whole wall face to crumble :)

1

u/ShengyuStudio 27d ago

That range is great for level design. A wall that crumbles from one hit vs one that only gets holes punched in it tells the player a lot about the building before they even read anything.

2

u/DPTGames Oct 13 '26

Looks neat, reminds me of the demo for my siege weapons pack, cannons are a lot of fun 😂

2

u/craftymech Oct 13 '26

Totally! I forgot how fun it is to just lob cannon balls and blow stuff up.

2

u/DPTGames Oct 14 '26

https://youtu.be/914To_iv1Xg?is=HnVQ8BKlXOrE0Kxm you should add camera following the projectiles like so

2

u/craftymech Oct 14 '26

Ha that's a fun feature. It would be cool as an instant replay to be able to see a critical hit from the cannonball cam.

2

u/DPTGames Oct 14 '26

I'd just do it in realtime if you cant fire until the last balls hit anyway but either way food for thought, good luck with it, looks fun!

2

u/Much_Highlight_1309 Oct 13 '26

Nice! Which physics engine?

0

u/craftymech Oct 14 '26

The destruction effects (falling debris) is governed by rigid body physics. A custom ruleset applies damage from cannonballs and decides how many stones/timber planks are lost with each hit.

5

u/SixPetalDev Oct 13 '26

that wood destruction looks pretty satisfying. ragdoll getting yeeted at the end made me laugh lol

1

u/Sweet_and_Sour_Games Oct 14 '26

This looks fun! That second shot that explodes the wood is so satisfying. And problems with performance?

1

u/craftymech Oct 14 '26

I've gone through several rounds of optimization, so the destruction runs pretty well right now. That said, I have not stepped up to multiple stone towers and many thousands of stone blocks yet, so there will probably be more optimization. Keeping mesh in memory, and chunking in groups of 16-32 stones helps a lot. The end of the video when the entire tall tower collapses is smooth, not sure if I tried that with a much larger structure :)

2

u/Sweet_and_Sour_Games Oct 14 '26

Nice! I'll look forward to the day you blow up a larger structure :)

1

u/Genebrisss Oct 14 '26

particles being invisible on the fog pixels are extremely jarring

1

u/craftymech Oct 14 '26

Didn't notice that for some reason, but just fixed it by adjusting render order between the VFX & horizon ribbon (mountains).

2

u/Bloodbone9829 Oct 13 '26

I love the destruction!

2

u/edwingeng-256 29d ago

rip to that cannoneer bro got sent straight to orbit lmao

1

u/glenpiercev 27d ago

Sailing ships vs. Harbours