Ask coding questions

← Back to all posts
edge collision in kaboom js
h
cannonthepom123 (14)

I'm making pong with kaoom.js. how do I get my ball object to detect collisions with the edge of the map/board/screen/edge

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

you can just compare the position lol

let ball = add([... code to add ball...]);

if (ball.pos.x < 0) // too left
if (ball.pos.x > width()) // too right
if (ball.pos.y < 0) // too top
if (ball.pos.y > height()) // too bottom