This is my first Java program I have ever made and I was trying to make an ai that predicts the location of the ball, that works fine but. Sometimes when the ball hits the very corner of the paddle it goes through the paddle. I know this is because it hits the speed is reversed twice for some reason
if ((yball > ypaddle) && (yball < ypaddle+120) && ((xball == xpaddle+39) || (xball < xpaddle+39) && (xball > 0))){
if(failsafe == 0){
xSpeed*= -1;
playerHit.play();
failsafe+=1;
counter = 0;
if(speed == maxSpeed){
float nothing = 0;
}
else{
if (xSpeed > 0){
xSpeed += increment;
}
else{
xSpeed -= increment;
}
}
if (ySpeed < 0){
ySpeed -= increment;
}
else{
ySpeed += increment;
}
}
These are the dimensions of the paddle rect(0, 50, 20, 100);