- Home /
Destroying an object on collide depending on the impulse magnitude.
I want to make trees that can be destroyed by a vehicle. I want the tree to be destroyed beyond some impulse force (let's say impulseThreshold
), and the car to react to the hit by losing some of the velocity , but keep going. If the impulse force is lower than impulseThreshold
, the car should stop, and the tree should be kept intact.
What I have now: When the vehicle hits the tree, the vehicle stops (like after hitting a "static" - i.e. non-moving - collider) and the threshold check is done in the tree's OnCollisionEnter() method. The tree gets destroyed or not depending on the collision.impulse.magnitude
value, and some fabulous cell fracture happens. The problem is: I want the vehicle to stop only when the hit force was not big enough to destroy the tree.
My idea: I wanted to get collision info (in OnCollisionEnter) and apply the hit impulse to the vehicle (with the magnitude of impulseThreshold
if the hit force was greater than the threshold or the hit force if it wasn't), but that would require the vehicle's collider to actually not react to the collision (as I would be simulating it myself). I also tried to use Triggers, but they provide no collision info - so I can't apply the force properly.
Any suggestions on how can I achieve that?
Your answer
Follow this Question
Related Questions
Character collider falls away unless "isTrigger" selected 1 Answer
Inconsistent behaviour in child triggers 1 Answer
Colliding two GameObjects 1 Answer
Colliders that do not collide... 1 Answer