Hey all! I've been having troubles with my current project, been trying to solve it for MONTHS! I cannot figure out how to get that mario style of collision detection into my game! The project generates each chunk of screen with bunches of blocks.

My failure of a method consists of checking each block in a forloop for detection, then deciding via distance which side the character is closest to and taking the appropriate action. Its so sloppy, jittery, and glitchy, I need something SOLID! Any ideas im desperate here. For all the experience I have this seems insane how I cannot figure this out.

A list of things I'd like to accomplish:

Solid character landing, he falls through the ground on occasion.
Solid wall collision, he walks through them sometimes as well.
The character for some reason flies up to the top of every section of blocks no matter what for some reason, I'd like to eliminate this.
The character needs to bounce off the bottom of the platforms.

While it's nice you're trying to come up with your own collision algorithm, it would be much easier for you to choose and implement an already made collision algorithm, engine or simply make use of flash's built in functions which should suffice in this case.

AS3 has two good functions for this, hitTestObject and hitTestPoint.

Simply put, hitTestObject tests for overlap of the bounding boxes between two movieclips, and returns true if there is an overlap.

if(MC1.hitTestObject(MC2)){
//COllision!
}

While this is nice, it doesn't really tell you where the point of collision is. hitTestPoint can be more accurate. hitTestPoint checks for collision between a point and a movieclip.

So if you do:

if(MC1.hitTestPoint(100,100,true)){
//Collision!
}

The code in the if statement will work as long as the point (100,100) is touching anything on the shape of the movieclip, not the bounding box. So even if your character isn't rectangular, this will only return true as long as it's hitting the actual character. So how do you use this for your character collision? Simply replace (100,100) with a point on your character that you wish to test.

if(Ground.hitTestPoint(player.x,player.y + 50,true)){
//collision
}

Assuming the player's registration point is in the center, and the height is 100. The point (player.x,player.y+50) will be a point on the bottom of the player. So what you want to do when reaching this point is colliding is push the player up. For it to look good, one way to do it would be to place this condition in a while loop, such that as long as the player is colliding, the loop will keep running until he is no longer colliding.

Now just do the same for all four sides, placing one point on each side (or more if you want more accuracy) and you get mostly perfect collisions.

Hope this helped and feel free to ask again if anything is unclear or if you need anymore help!

hitTestPoint() and hitTestObject() have their pros and cons. For a Mario-styled game, I personally prefer to code my own hit tests as well, based on basic math. If done right, this may result in a really smooth running and light game.