- Home /
How to calculate improved car impact damage value?
Hi, Getting the value of impact is easy: using the relativeVelocity of the Collision field in
void OnCollisionEnter(Collision col){
impactSpeed = col.relativeVelocity.magnitude;
//do further instructions with impactSpeed...
}
Done. But, since I am writing here, you anticipate that this is not the best approach.
.
The problem with having only col.relativeVelocity.magnitude as your damage source is that you wreck your car when you are touching a wall at the side of it and maintain driving.
.
That is caused since it will return the cars velocity because the wall has no velocity (static).
.
Obviously the wanted damage should be low due to no/minimal velocity loss.
.
But substracting the cars' velocity to correct that doesnt help, it will give a value that is not lim->0.
impactSpeed = (col.relativeVelocity - rb.velocity).magnitude; //should equal to rb.velocity - rb.velocity with non rigidboy collisions and (2*rb.velocity) - rb.velocity if 2 cars are colliding with same speed
So how to give a higher damage when the crash would stop the car more than a bump?
Is there an accurate formula for that?
Answer by Namey5 · Aug 21, 2019 at 03:28 PM
In my damage system, to get around that issue I took the absolute dot product of the relative velocity with the collision's hit normal and adjusted the impact based on that (that way objects colliding towards each other will do significantly more damage than those that are adjacent to each other), i.e.
impactSpeed = col.relativeVelocity * Mathf.Abs (Vector3.Dot (col.relativeVelocity.normalized, col.normal));
I then just played around with some static modifiers until it looked decent.
'Collision2D' does not contain a definition for 'normal' and no accessible extension method 'normal' accepting a first argument of type 'Collision2D' could be found
Both the question and this answer were made with a 3D game in $$anonymous$$d. It's not unreasonable that Collision and Collision2D are different from each other. Despite that, you're not wrong, but it's also not really the point.
Regardless, while the answer also skipped a step, the goal was sound regardless. For any collision (2D or 3D), there are one or more points of contact. Assu$$anonymous$$g the first contact is desired (a common, albeit not universal case), you would use something more like collision.GetContact(0).normal
to get the normal value of the surface.
Your answer
Follow this Question
Related Questions
Rocket projectile damage not applied on collision (message not sent/received) 1 Answer
Objects should simulate the real world like FPC 1 Answer
Damage by collision with ridgidbodies 1 Answer
On collision deal damage each few seconds and doesn't keep consistent collision? 1 Answer
How to Detect Collision, Calculate Velocity+Mass, Apply Damage 0 Answers