   trouble with collision
  Hey everyone,So I'm trying to make collision detection that only stops my character from moving if the top of my character touches the bottom of the object, not the other sides.So this is the Lazyfoo collision I have been using:bool check_collision( SDL_Rect A, SDL_Rect B ){    //The sides of the rectangles    int leftA, leftB;    int rightA, rightB;    int topA, topB;    int bottomA, bottomB;    //Calculate the sides of rect A    leftA = A.x;    rightA = A.x + A.w;    topA = A.y;    bottomA = A.y + A.h;    //Calculate the sides of rect B    leftB = B.x;    rightB = B.x + B.w;    topB = B.y;    bottomB = B.y + B.h;    //If any of the sides from A are outside of B    if( bottomA <= topB )    {   return false;    }    if( topA >= bottomB )    {   return false;    }    if( rightA <= leftB )    {   return false;    }    if( leftA >= rightB )    {   return false;    }    //If none of the sides from A are outside B    return true;}I tried modifying that code to make the collision only work with the top and bottom, so I changed the two last if statements like this: if( rightA <= leftB )    {   return true;    }    if( leftA >= rightB )    {   return true;    }It won't work, it makes my character stop moving left and right whenever the I'm aligned with the object left and right.Whats a fairly easy way to fix this?I'm writing this game in C++ with SDLThanks for the help.   
  Try returning extra information about the details of the collision, such as which edges of which rectangles are intersecting, then have the calling caller decide if it wants to ignore the collision:struct CollisionInfo {enum WhichEdge { EDGE_TOP = 1,EDGE_RIGHT = 2,EDGE_BOTTOM = 4,EDGE_LEFT = 8};WhichEdgemInFirst, mInSecond;};bool checkCollision( const SDL_Rect& A, const SDL_Rect& B, CollisionInfo* result ) {if ( /* collision */ ) {typedef CollisionInfo CI;if ( result )result->mInFirst = CI::EDGE_TOP | CI::EDGE_RIGHT /* or others */; // Find which edges are intersectingreturn true;}return false;}