Sure, explosive projectiles are one thing, but then you’ve to make things take damage… and die.
Gone to Pieces
This caused me no end of pain in Project Y4. I’m not a particularly good animator, and FK animations are not ideal for explosive break-ups as it is. I had a few half-hearted keel-over animations that were too fast or two slow, where I’d try my best to mask the shonky movements with blistering particles and swapping to a battered wreckage texture.
Making things fall over convincingly, it turns out, is a Very Hard Problem.
Luckily, this time around, Unity has a built-in physics engine.
The first answer to this problem came easily enough. In the six-day-prototype, I used a single mesh chopped into pieces — when the AP-AM there died, the entire thing replaced itself with the cut-up version and it fell to pieces. Job done? Nuh-uh.
The cut-up version of the mesh was not animated. Even if it was, it wouldn’t have been synched up to the motion of the unit that previously existed — it was something new, something independent. When the AP-AM died, you could see the pieces fall, not from the pose it held when the death-blow struck, but from the default standing position.
It might seem like a small thing but annoys the fuck out of me about Starcraft II — units with alternative death modes for burning and suchlike suffer from this very same lack of blending. Most obviously the infested terrans in that Raynor mission as they walk towards you and immediately revert to standing stock still as they are roasted by the fire car things.
So, while that old strategy works and should continue to work for static decorations, it’ll never fly for my units, my characters. Those mechs might be reasonably sized in terms of real scale (the Delta is maybe 5 or 6 metres tall), but they will take up quite a bit of screen space so I want them to be detailed. Since it’s not like I can compete on graphical fidelity, I’ve got to make do with other details. (Details that are, conveniently, more important to me anyway. Can’t make a good game if you’re not feelin’ it.)
Of course, that’s not the end.
It’s all very well to have things disintegrate, but nothing dies cleanly in this world. Large robots don’t just fall to pieces, they explode in a shower of fiery shrapnel.
That means you can’t just bring the pieces into existence, you have to apply force to them. Not just one force, though — you’ve got to combine the force of the explosion that killed the unit with force of the explosion from its own core plus the unit’s overall motion at the time of death… And you’ve got to adjust the force of each explosion by how far a given chunk is from the epicentre of the explosion…
The mathematical model is simplistic enough, but the results are totally worth it.
So my disintegration strategy involves making things out of pieces, as befits my dreams of modularity. I have an invisible skeleton that is the actual unit, upon which I dangle the discrete components that make it up — pelvis, thighs, calves, ankles (those are new; added so the Delta can sidestep), feet…
That’s quite a lot of stuff to hook up, so naturally I don’t want to have to do that by hand for every single unit I ever place in a scenario (especially when I want to dive into pseudo-random variation of individual components along the way). Before I could go near death and destruction, I first had to program a mechanism that would spawn my units based on simpler settings.
As is always the case, Unity threw some spanners in my works. Sometimes a missing piece would kill the entire game in an obvious way (that’s good, easy to fix), other times a forgotten component would silently leave the unit inactive (that’s bad, hard to find). Forgetting to give my invisible skeleton a renderer, for example (since, well, it’s invisible and so doesn’t need rendered — right?) meant that the animations never played. Forgetting to assign an AI behaviour (they still ominously turn to face the cursor) meant the unit wouldn’t even get to the point of being affected by gravity.
Okay, okay, those are the fault of my own internal scripts as much as my ham-fisted understanding of Unity and its methods. Either way, it took some wrangling. Actually wiring up the wreckage spawning after all that was a piece of cake — take an identical wreckage mesh and place it in exactly the same place as the dying part.