Hi I'm trying to make a simple pong game and I'm running into trouble with the collision detection. The ball is not registering with the paddle.
function moveBall() {
var rightRadius = ballX + radius;
var leftRadius = ballX -radius;
if (ballX + radius > canvas.width || ballX - radius < 0) {
ballOffX = -ballOffX;
}
/*
The following code is handling the collision of the ball with the plate
*/
if((rightRadius <= (player1.x + paddleWidth))&&(leftRadius >= player1.x) &&(player1.y == ballY + 10)){
ballOffY = -ballOffY;
}
ballX += ballOffX;
ballY += ballOffY;
}

player1.y == ballY + 10is your problem. You probably want an inequality, otherwise you're assuming that the ball will at some point be located at exactly thatyposition, which is unlikely given a dynamic velocity. - Patrick Roberts