javascript - collision detection not registering with ball -
hi i'm trying make simple pong game , i'm running trouble collision detection. ball not registering paddle.
function moveball() { var rightradius = ballx + radius; var leftradius = ballx -radius; if (ballx + radius > canvas.width || ballx - radius < 0) { balloffx = -balloffx; } /* following code handling collision of ball plate */ if((rightradius <= (player1.x + paddlewidth))&&(leftradius >= player1.x) &&(player1.y == bally + 10)){ balloffy = -balloffy; } ballx += balloffx; bally += balloffy; }
i made if statement sense collisions in javascript, here is:
if circle x < rect x + circle width && circle x + rect width > rect x && circle y < rect y + circle height && rect height + circle y > rect y {
this works putting ball inside of 'imaginary box' , when of edges of 'imaginary box' touch of edges of rectangle, collision detected.
Comments
Post a Comment