Hi i am trying to make the blue object collide with the green one, but I cannot get the whole area of the square, i only detect half....and down the entire Y + X axis's
if (blue.x >= green.x && blue.y >= green.y){
console.log('BOOM');
}
Hi i am trying to make the blue object collide with the green one, but I cannot get the whole area of the square, i only detect half....and down the entire Y + X axis's
if (blue.x >= green.x && blue.y >= green.y){
console.log('BOOM');
}
As mentioned by commenters above, you'll need to read up on rectangle collision detection. Checking if (rect1.x == rect2.x && rect1.y == rect2.y)
will only ever be true if both rectangles are originating from the exact same set of points (i.e. they are overlapping from the same x and y origins).