race collisions

hello. i’m working on a racing game right now and when my car enter in collision with a wall he dies or else he gets friction and the speed is decremented. The problem is that those collisions aplly to the other cars two when I hit them but I dont want my cars to destroy each other when they collide I want them only to bump each other.

here is my code

 void OnCollisionStay(Collision death)
    {
        if (death.contacts.Length > 0)
        {
            if (Vector3.Dot(death.contacts[0].normal, floor) < treshold)
            {
                if (Vector3.Dot(death.contacts[0].normal, moveDirection.normalized) <= fricTreshold  currentSpeed >= 20)
                {
                    gameObject.SetActiveRecursively(false);
                    currentSpeed = 0;
                    Invoke("Respawn", 2);
                }
                else
                {
                    currentSpeed *= forcedBrake;
                }
            }
        }
    }

is it better to use a tag or something else?

I believe you should look at the OnCollisionEnter. Use the relativeVelocity.magnitude of the impact to determine if it is severe enough to cause the player to die, so at a magnitude of 2 or better he gets damaged and his maximum speed is reduced, but at a magnitude of 5 he is no longer capable of racing, thus dead.

This also being said, you can look at the relativeVelocity vs the relative direction of the vehicle. If he heads straight into the wall, he gets damage modifiers, but if he just grazes it it’s not so bad. (the magnitude will kind of show this, but not as well)

As far as if he hits the wall he slows down, thats a given. After all, you are using a physics engine, let it do its job.

Ty for the tip I’l try this right away :slight_smile: