I have a ball class with the following variables:
int x,y,width,height;
double velX,velY;
I want to make it so that whenever the ball hits a block, it bounces and it looses some velocity.
//Gravity & movement for the ball
ball.setVelY(ball.getVelY() + 0.2);
ball.setY((int)(ball.getY() + ball.getVelY()));
//Make the ball bounce.
if(ball.getBounds().intersects(block.getBounds()){
ball.setVelY(ball.getVelY() * -0.7);
}
I thought this would make the ball bounce slowly until it was barley moving at all (which I would test for and then have the ball stop completely,) but this is not the case. The ball will bounce several times normally with each bounce being smaller than the one before. However, after a few bounces, the ball will stop bouncing lower than previous bounces. Why is this and what should I do to fix it?