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;  } 

enter image description here

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

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -