After you calculate all the forces influencing your character, you have the resultant force as a 2D vector.
You can verify the numerical signs
of the components of this force to know which sides of the box are the front sides, which are the sides facing towards the direction of movement.
The sign of the X component of the force indicates whether a frontal side of the box will be the left or right one, and the sign of the Y component of the force indicates if the other frontal side is up or down. When the force is completely horizontal or vertical so one of the components of the force has a sign of "zero," you will have a single frontal side.
It is these front
sides that will collide against the back
sides of the other boxes - the front sides of a box can only collide against the back sides of another box, you will never have back-back or front-front side collision.
This helps avoiding a common issue where your character can skip obstacles if it moves more than the width or the height of its collision box on a single frame.
You can use the old frame position for the back sides of the character's box and use the new
position for the front sides of the character's box (the position of the front sides after they are moved). This way you don't have a box anymore, but an extruded "shape" that represents the full motion of the character for that frame, and it is something that always seems pass tests no matter the speed of the character.
You can still use rectangle intersections with this. You would supply the coordinates of the top-left corner and the bottom-right corner of the screen area (or bounding box) occupied by this shape as a rectangle to be tested against the others. While this is an approximation, it seems to convey the illusion to great effect.
When a collision is detected, instead of simply stopping the character, you need to move it as much as it is possible to move both horizontally and vertically until it reaches the obstacle. This is simple to calculate based on the position and boundaries of the character and the position and boundaries of the obstacle. This makes the character gently touch a wall instead of keeping a distance from it, in case the character moves farther than its width or height.
Edited by Kryzon, 20 January 2014 - 02:07 PM.
Something I used in a project is checking collisions between the front sides of a moving box against the back sides of the others.