Is it possible to implement a conditional collision response?

In my project I have the following:

  • a large-ish number of fixed objects that don’t move, but have a “health” value.

  • a small number of moving objects that can collide with these fixed objects.

I need to do this:

  • Upon a collision, the fixed object’s health value gets reduced by an amount that is dependent on the speed of the moving object.
  • If the fixed object’s health value reaches zero, it is destroyed and the moving object continues to move with little (or preferably zero) impact on it’s velocity.
  • If the health value doesn’t reach zero, the moving object bounces off as if it has hit an immovable object.

From looking around in the online docs, I’m wondering if this is even possible in Unity. It seems that once the collision has been detected, the response will occur. However, admittedly I’m new to Unity so I could be overlooking something glaringly obvious.

It sounds like you want the moving object to ‘react’ to the collision all the way up to the point of ‘zero health’ on the static object. Correct?

If so, have you considered making the collider into a “trigger” when the health is less than 1? “IsTrigger” is a property of Collider components. That way, the trigger would detect the moving object but there would be no reaction.

I’ve pretty much got it working as intended now, without having to write custom physics behaviour. I used a slightly larger outer collider, which conditionally switches the inner collider to a trigger when the colliding object is moving fast enough to destroy (and pass through) the static object. I have a few edge cases to tidy up, but essentially I think that’s going to do what I need.