Collision Car Sensors

Hello,
I am trying to introduce a damage-System for my car game like the ones in Destruction Derby. I have thought about 6 sensors which are located at their specific positions of the car: frontLeft, frontRight, middleLeft, middleRight, rearLeft, rearRight(see image below at CarStatus):


look at CarDamageStatus

Because I am new to Unity I don’t know much how to do this. Shall I split the copied and invisible carmesh into 6 parts and let them be the sensors which the script is continiously looking whether they are colliding and if true send the Hit-Count converted in color (green=noHit;red=maxHit) to the UI-triangles?

  1. So far I have written the color-assign part:

GameObject.Find(“Damage_FD”).GetComponent(RawImage).color
= Color.Lerp(Color32(255,0,0,125), Color32(84,255,0,125), hp_FD);

Damage_FD.getComponent(RawImage).color is the Front-Drivers UI-Image-color.

Color32(255,0,0,125) is full Red (alpha ~ 0.5).

Color32(84,255,0,125) is Green (alpha ~ 0.5) with HSV value 100, so it fits for the start value of hp_FD.

hp_FD is the Lifepoints in int starting usually from 100 (no damage on this sensor) to 0 (max damage).

This above works for all 5 other sensors. But the color changes not smoothly according to the hp_SENSOR values. It changes, when they are 0 from green to red and not gradiently.

The mesh-replacement-function is in thought way easier: When the Hit-Count of the sensors reaches something other than 0, then the trunk as an example for rearRight or rearLeft-sensors is replaced with a damaged trunk and so on for the other sensors.

But the sensor indication needs to be working first to go on further with the replacement.

Any help is appreciated :slight_smile:

Some old-school damage modeling!

You should “split” your meshes into logically sensible chunks you can swap in and out as needed. The actual collision detection can and should be handled by simplified convex shapes. You might get by with six box-colliders arranged to correspond to the six desired areas. Mesh colliders are fine too, but you should adhere to the best practices associated with creating good mesh colliders; these are common-sense modeling practices, info can be found here and there if needed.

If you wanted to get a little fancier, you could use some simple physics math to scale the damage received based on the momentum of the impact. That way it’d take 50 fender-benders to equal the damage of a single head-on high-speed collision, etc…