how to clamp( set max value) the velocity of a 2d rigidbody?

I’m making a typical block breaker game aka arkanoid, but I’m facing a problem with the ball getting a very big velocity as the game goes on, which I believe is due to:

1- the bounciness of the physics material which is set to 1

2- the force add to the ball through the paddle

to the point where it just penetrates through my boarders which are static 2d box collider.
I managed to over come the problem by always checking the position of the ball and in case it is out of the view restart it’s position and velocity, so in way this works but I want to prevent this from happening in the first place by setting limits to the balls velocity.

Try adding this into the code of your game object.

float maxVelocity = 10;
Void FixedUpdate()
{
rigidbody2D.velocity = Vector2.ClampMagnitude(rigidbody2D.velocity.magnitude, maxVelocity);
}

You could also check rigidbody2D.velocity.magnitude before adding the paddle force. If it is bigger than the maximum value, do not add the force.