wall friction

Hello guys. here’s my problem. I’m doing a race game and I want my car to lose speed when it collide on the walls from his side so far I have

void OnCollisionEnter(Collision friction)
{
foreach (ContactPoint cote in friction.contacts)
{
Debug.DrawRay(cote.point, cote.normal, Color.cyan);
}
currentSpeed *= forcedBrake;

}

forcedBrake is my decceleration variable

the problem is it does not deccelerate when I get on the walls

If you’re letting the physics engine handle it, it will apply friction for you. Otherwise, that will work, only if forcedBrake is < 1, otherwise, it will just keep the same or speed it up more. Also, without seeing the whole script, I can’t help any more than that.

Good luck :slight_smile:

OnCollisionEnter only triggers once when the collision begins.
OnCollisionStay triggers continuously while a collision is happening.

Might help to switch over, depending on how your cars hit your walls.

ty guys it was great help I got a problem solved with OnCollisionStay instead of OnCollisionEnter juste a las problem to solve and I’l have it done ^^