//tells collision of ball with paddle
void contactPaddle() {
//left paddle collision with ball
if(x - w/2 < paddleXL + paddleW/2 && y - h/2 < paddleYL + paddleH/2 && y + h/2 > paddleYL - paddleH/2) {
if(speedX < 0) {
speedX = -speedX;
}
}
//right paddle collision with ball
else if(x + w/2 > paddleXR - paddleW/2 && y - h/2 < paddleYR + paddleH/2 && y + h/2 > paddleYR - paddleH/2) {
if(speedX > 0) {
speedX = -speedX;
}
}
}
This is the code i’m using for creating collision between my ball and paddle in a pong game. Im trying to figure out how to randomize which direction . the ball goes after touching the paddle to make it more difficult. Anyone have an idea?