Ask coding questions

← Back to all posts
how do i detect if the ball hits the square (collison)
r3b0rn (28)

how do i detect if the ball hits the square (collison)

Answered by Coder100 (18199) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18199)

you could check if the x and y position of the circle is greater than the x of the rect and the y of the rect respectively and also if it is less than the x+width of the rect and y+height of the rect respectively too.

if (x > rx && y > ry && x < rx + width && y < ry + height)

where x and y is the position of the circle and rx and ry is the position of the rect and width and height is the width and height of the rect.

r3b0rn (28)

@Coder100
if (ball.x > player.x && ball.y > player.y && ball.x < player.x + player.width && ball.y < player.y + player.height){
document.write("end game")
}
so this basically?

r3b0rn (28)

play in full screen probably!