Damage is done

Well, it took me long enough, but finally the damage system is complete!  Most of the time was actually spent doing optimisation work, which I’ve discussed before in previous posts, the damage system itself didn’t take that long to do.

On the idea scrapheap

My original idea for damage was that each attachment between parts (fixed, rotary, linear, etc.) would have a “health” value.  Then upon a collision contact with a part, some damage amount would be propagated out to all of that part’s attachments.  For each attachment, damage would effectively accumulate over time as its health value gradually reduced, until it reached zero at which point the attachment would be deleted.

However, there were problems with this method:-

  • Deleting individual attachments due to damage would lead to inter-penetration issues, just like when you manually delete attachments with the builder tool.
  • Each attachment having a health value would need to be conveyed somehow to the player via a UI, and I couldn’t think of a way which wouldn’t be messy and confusing.
  • Because damage is applied for every collision contact (of which there can be many), the code is quite performance sensitive, and so needs to be as lightweight and simple as possible, which this method wasn’t.

Binary break

So in the end I went with a simpler solution that just uses a “strength” threshold.  When a part receives a collision contact, I simply compare the impact force with the part’s strength value, and if the force is greater than this value, I break the part off (i.e. delete all of its attachments), otherwise I leave it attached.  In other words, a part is either entirely broken off or it isn’t, there’s no intermediate damage state or health values to deal with.

Happily, I found was that there was not really any need to explicitly propagate the damage force to neighbouring parts to achieve a convincing effect.  Direct impacts seem to be enough, I think because as parts break off they hit other parts and the damage sort of propagates organically.

I’ve also finished the implementation of explosives that integrates with the same damage system, in this case the damage force is simply derived from a linear fall off from the explosion centre.  The resultant bits that are broken off then have an explosion force applied to them to push them around, seems to work pretty well.

Lastly, I’ve also added a per-construction setting to enable / disable invulnerability (i.e. immunity from part breakage), as sometimes it could be useful to disable damage for those particularly “experimental” constructions that might try and smash themselves to bits.

Still to do

As I mentioned, each part has a strength value which basically determines how hard it is to break off.  A part’s strength value is intended to reflect the material it’s made from (e.g. steel is stronger than wood or plastic), and I still need to fine tune these strength values to get the balance correct and hopefully give a nice trade off between the various materials.

Also, I’m thinking I might bias each part’s strength value slightly based on the number of attachments it has, so that the more other parts it’s attached to, the harder it is to break off.  Again, hopefully giving the player further interesting trade offs to choose between when building their constructions.