-3

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');
  }
2
  • 1
    You'll need to post a complete code example. That little snippet isn't going to cut it. Commented May 11, 2014 at 20:01
  • 1
    If you google "collision detection rectangles" you'll find many tutorials on how to do this. Commented May 11, 2014 at 20:02

1 Answer 1

0

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).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.