   Two rectangles/bounding boxes intersection for collision detection
  Hello,Im trying to get my collision detection working properly. I don't think my current method of checking the intersection of two given rectangles are correct.bool BoundingRectangle::Intersects(Polygon& poly){return ((poly.GetX() <= GetRightX())&& (poly.GetRightX() >= GetX())&& (poly.GetY() <= GetBottomY())&& (poly.GetBottomY() >= GetY()));}For instance. I have a surface layed out for about 600 pixels, than another for about 500 pixels. Over the second one is another surface which is like 300 pixels or so. With my current collision check function (see below) i add a break when an intersection is detected with one of the surface objects. That works for the most part in terms of the player staying on top of the surfaces. However, it does seem to break my code that when the player falls below the screen, he/she gets reset to the start. Instead of resetting, the player keeps falling.If I remove the break call, what happens is on the first surface, half the body is below the surface, the other half on top. The jump doesn't work quite right either. When i get over to the elevated surface, I can jump on it fine. I think this has to do with how my Intersect function works. Below is some screenshots of what I am referring to.bool CheckGroundCollision(std::vector<Surface>& surfaces, Player& player, bool& jumpInitiated){bool intersects = false;std::vector<Surface>::iterator it;for(it = surfaces.begin(); it != surfaces.end(); it++){Surface* tempSurface = &(*it);intersects = tempSurface->GetBounds()->Intersects(player);if(intersects){player.SetY(tempSurface->GetY() - player.GetSizeY());jumpInitiated = false;break;}}return intersects;}Working screenshotWith break commentedIn case it matters, I am using SFML for this.[Edited by - agm_ultimatex on May 16, 2010 3:15:42 PM]
  both screenshots look exactly the same to me :Pare you reseting the players BoundingRectangle after he falls?looking at the code, removing the break might not be a great idea.it will just continue to look through each BoundingR, and whichever Box was last checked, is what will always be returned.So aslong as your player isnt colliding with the Last Box in the game, youll always have False returned.   ;  Hmm, that's a good point. Plus it saves time having to loop through certain elements. I fixed the link for the break commented image, sorry about that.   