How to restrict how far an object can decrease size?

I currently have a rectangle shrinking its size upon impact with a ball, is there any way I can make sure that once it shrinks to a certain size it stops shrinking and just remains that size?

void paddle(PVector pad){;
  if (ballLoc.x +ballsize/2>pad.x -playerW/2&&
  ballLoc.x -ballsize/2<pad.x +playerW/2&&
  ballLoc.y +ballsize/2>pad.y -playerH/2&&
  ballLoc.y -ballsize/2<pad.y +playerH/2){
  speedX *=-1;

The second to last line is decreasing height of rectangle each time but I want it to stop after lets say it hits 20. What could I state in the code to do so?

1 Like

Hi MartinM,
Have your researched what a for-loop is? I think it would be a very nice solution to your problem.

I guess playerH is your size?
You have to check your size before shrinking:

if (playerH > 20) {

Then you only can shrink if your size is big enough (> 20 in this case).

playerH = max(playerH - 5, 20);

Thank you I actually had not thought about using a for loop to solve my issue I was rather thinking of just another way to implement the if statement but a for-loop would work wonders