   Post-Collision conditions
  I have no problem getting collision to work correctly on all edges on a rectangle, so collision is not the issue I am having just to make this clear. What I am having an issue with is post-collision conditions. Lets say I am moving a rectangle like this,if(input.keydown(w))   sprite.y -= movement;if(input.keydown(s))   sprite.y += movement;//.....Once collision is found if I want to stop all movement I could just set movement to 0, but here is the problem if my sprite.rect.right collides with object.rect.left, I should be able to move up, down, and left still not disable movement all together and I want it to be the same for every other side as well, so this would be a top-down view. My problem is this, if I collide on any side I cannot figure out how to keep movement in other directions except the collision side, anyone have any ideas on this or know how I can go about doing this?if(collision(sprite, object)){//problem here....}
  The simplest way, if your rectangle/rectangle test is fairly cheap (which it should be) is to separate the movement into two steps and do a collision test twice.So:int xm,ym; // get movement deltas for frame from keyboardx+=xm;if(collides())    {    move_x_out(); // move so objects align horizontally along collision edge    }y+=ym;if(collides())    {    move_y_out(); // move so objects align vertically along collision edge    }This is a method I've used when working with just axis-aligned bounding box collisions extensively in the past and produces the sliding behaviour you seem to want.A more sophisticated method that only requires one collision is to calculate the penetration depth of the rectangles and move the rectangle out along whichever axis has the minimum penetration, similar to the method used for collision response in separating axis theorum, but without the complications of projection since AABB's projections onto the relevant axes are just equal to the x and y components of their corners.This approach can, however, lead to some incorrect corner cases where objects can slide out of the wrong side, especially when fast moving. This is normally not noticeable.   