I am trying to write a damage system, similar to Flatout 2, but I can’t find a good solution.
I got two cars, each is trying to hit the other with the highest speed possible. If car1 hits car2, which is not moving, car2 should get the damage of the magnitude of the colliosion strength. if car1 hits car2, which is moving towards car1, car1 should also get damage. The problem I am not able to solve is happening when car1 is hitting car2 in the side, while car2 is moving perpendicular to car1. If thats the case only car2 should get damage and car1 should not, because car2 is not moving towards car1.
I tried using the dot product of both relativ speeds of the cars, but couldn’t get it to work…
If someone knows a method or way to deal damage based on the relativ speed of the object, that the player is colliding with in comparison to the players transform, please tell me. I hope you get what I am trying to explain, any help would be highly appreciated. Thank you!
I know very little about physics, and this definitely wouldn’t be realistic… but an idea.
I’m thinking this from imaginary TakeDamage method’s viewpoint:
How about you multiply damage caused by velocity by direction of hit?
If forward or back hit, full damage, if closer to perpendicular hit, 0 damage to self. Vector angle could be enought for this purpose.
You could also then multiply this by the velocity of colliding object, i.e. head on or rear collision to non-moving car will give less or 0 damage to car that is ramming static car.
One solution is to get the dot product of a car’s velocity and the vector towards the center of the other car’s front bumper (maybe slightly offset towards the back), and use that ratio somewhere in the damage calculation. Damage occurs if and only if the dot products of the car’s velocities is below some threshold.
Case1: You T-bone another car. You have a forward velocity component, and the Vector from front your car’s center to the front and center of the other car is positive. Positive dot product, you damage them.
Case2: You are T-boned. You have a forward velocity component and the other car’s front is behind your car’s front from your perspective. Negative dot product, you don’t damage them (and they damage you).
Case3: Driving in the same direction and colliding. The dot product of your velocities is too high and no one takes damage.
Case4: You T-bone, but only barely clip them with your left front bumper. Both cars have positive dot products towards each other and both cars take damage.
Case5: Head-on collision. Both cars have positive dot products towards each other from their frame of reference and both cars take damage.