How to set a limit for ridgidbodies speed

Viewed 68

I have been working on a game with cars but they go to infinite speeds, and that's not nice.

I have no idea how to do it I tried rb.speed and stuff but I don't know how.

1 Answers

After saving rigidbody and defining a variable for speed limit, just limit it with Vector3.ClampMagnitude.

public float maxVelocity;

void FixedUpdate()
{
    ///... Add force

    rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxVelocity);
}
Related