void OnCollisionEnter(Collision coll) { if (_replayer) { return; } if (Race.Current == null) { return; } if (!Race.Current.Started) { return; } if (Crash3AudioSource == null) { return; } Damg = false; if (name.StartsWith("Menu")) { return; } if (_rb.velocity.sqrMagnitude < 8) { StationaryCollision = true; } else { StationaryCollision = false; } foreach (ContactPoint cont in coll.contacts) { Collider colldr = cont.thisCollider; try { if (cont.thisCollider.sharedMaterial.name == "CarBodyPhysicsMaterial" && cont.normal.y > 0.5f) { cont.thisCollider.sharedMaterial = StickyCarBodyPhysicsMaterial; } } catch { } if (colldr.name.StartsWith("V") || colldr.name.StartsWith("Coll")) { string colldrName = colldrMap[colldr.GetInstanceID()]; Vector3 Impulse = transform.InverseTransformVector(coll.impulse); Vector3 relVel = transform.InverseTransformVector(coll.relativeVelocity); float relVelSqrMag = relVel.sqrMagnitude; Vector3 localPoint = transform.InverseTransformPoint(cont.point); if (colldrName == "ColldrF" && localPoint.y > 0.5f) //so you dont get kerb collisions && relVel.sqrMagnitude > 200) { if (localPoint.x < -0.5f) { Scratch(partsMap["FLWing"]); if (relVelSqrMag > 200 && relVelSqrMag < 800) { Damage(partsMap["FLWing"], "Crunch"); } if (relVelSqrMag > 800) { BreakOffPart(partsMap["FLWing"]); } } else if (localPoint.x < 0.5f) { Scratch(partsMap["Grille"]); if (relVelSqrMag > 600) { BreakOffPart(partsMap["Grille"]); } } else { Scratch(partsMap["FRWing"]); if (relVelSqrMag > 200 && relVelSqrMag < 800) { Damage(partsMap["FRWing"], "Crunch"); } if (relVelSqrMag > 800) { BreakOffPart(partsMap["FRWing"]); } } } if (colldrName == "ColldrLRWheelarch") { Scratch(partsMap["RLWing"]); if (relVel.x > 600) { BreakOffPart(partsMap["RLWing"]); } } if (colldrName == "ColldrRRWheelarch") { Scratch(partsMap["RRWing"]); if (relVel.x < -600) { BreakOffPart(partsMap["RRWing"]); } } if (colldrName == "ColldrRFootplate") { Scratch(partsMap["RFootplate"]); Scratch(partsMap["FRDoor"]); Scratch(partsMap["RHood"]); Scratch(partsMap["CarBody"]); if (relVelSqrMag > 400 && relVelSqrMag < 1000) { AddHinge(partsMap["RFootplate"], "RFootplate"); } if (relVelSqrMag > 1000) { BreakOffPart(partsMap["RFootplate"]); } } if (colldrName == "ColldrLFootplate") { Scratch(partsMap["LFootplate"]); Scratch(partsMap["FLDoor"]); Scratch(partsMap["LHood"]); if (relVelSqrMag > 1000) { BreakOffPart(partsMap["LFootplate"]); } else { AddHinge(partsMap["FLDoor"], "FLDoor"); } } if (colldrName == "ColldrLSide") { Scratch(partsMap["CarBody"]); if (Mathf.Abs(Impulse.x) > 600) { Damage(partsMap["FLDoor"], "Crunch"); AddHinge(partsMap["FLDoor"], "FLDoor"); } if (Mathf.Abs(Impulse.z) > 500) { BreakOffPart(partsMap["FLDoor"]); } } if (colldrName == "ColldrRoof") { Damage(partsMap["Roof"], "Crunch"); } if (colldrName == "ColldrTrunk" && Mathf.Abs(Impulse.z) > 1000) { Damage(partsMap["Tail"], "Crunch"); Scratch(partsMap["Tail"]); Scratch(partsMap["Trunk"]); Scratch(partsMap["RLWing"]); Scratch(partsMap["RRWing"]); } if (Damg == false && !Crash3AudioSource.isPlaying) { Crash3AudioSource.pitch = Random.Range(0.17f, 0.26f); Crash3AudioSource.volume = Mathf.Clamp01(coll.relativeVelocity.magnitude / 20); Crash3AudioSource.Play(); } } } //Tell the GPS that we've hit a fence so the drift fails if (coll.collider.name.StartsWith("RoadSec") && Gps != null) { Gps.CollideRoadSection(); } }