I'm making a somewhat simple side-scroller in Flash. The way I'm currently doing the really basic physics(you don't fall through floors/can't walk through walls) is that I have a big symbol of all the walls/floor/ceiling and use some complex hit testing against that.

Basically, if you are moving down when you hit, move you up til you're out, moving left move right, etc. If you're moving diagonally you'll move diagonally out and then move over the direction that didn't get you out until you hit something or get lined up. Then I move you down one so you're touching the floor since I have you fall down 20 pixels if you're in the air, and that make it slow since it has to do 20 hit tests every frame.
Here's the code I use:

This is working okay for now, and you can see a demo of it here, but there are a couple of problems.

For one, it can get a little slow, but this isn't that big of a problem, since it's pretty rare, and it's not that slow. Mainly, it's that when I get around to animating the little dude, and even now sometimes when it messes up a bit, it will get more than five pixels in the wall. Then when I try to move out, it won't make it out in one frame, and it will force him through the wall the wrong way, making him fall into infinity...does anyone know how to fix this? Should I totally redo how I do it? Should I have some kind of variable for which way he came from? If so, how should I do it?

Doesn't really answer the question. It is not really possible to port an existing game to Flixel without rewriting the whole thing.
–
IainAug 4 '10 at 22:29

1

Of course. But what it does do is solves the problem of performance and lack of physics knowledge. Create games, not wheels.
–
David McGrawAug 4 '10 at 23:02

I've decided to go with Box2D. I've kinda cancelled work on my game until I figure out how it works, and I found a great set of tutorials here: kerp.net/box2d/index.php Since you mentioned Box2D first, I'll accept yours even if it is really late. :p
–
UllallullooAug 20 '10 at 16:50

It's hard to comment on speed since we don't know what's happening in HitTest.complexHitTestObject. I would say though that if you have a point that represent the player's feet, you can just move that point straight up in a while loop until you hit the air. I would have 2 "detector" points, one on the bottom left corner of the character, one on the bottom right, and test the leading point against terrain and move the character back until they are out of terrain (as you are doing). If you are using the built-in hitTest methods be aware that they are not that fast, but may well be the only way to get the effect you want.