Uneven terrain collision detection

I making a lander style game where you fly around and save penguins (dont ask!) and then you fly your helicopter to a landing pad. There is along way to go, but the collision detection wont work and im out of ideas! Here is the problem:

Here is the swf

Ive used this as the basis of the hit collection, a sentry/perimeter setup. There is a perimeter set around the helicopter, and one set around the ground. If they two hit each other, then some code moves them apart. It works really well. But sometimes, the helicopter gets stuck inside the the ground (see swf). Here is the code that does the testing:

ground_collision = function(l, o) {
    
    var c=0;
    var xs=0;
    var ys=0;
    var diff=0;

    for (i in l.perim) {
            
        l.perim.localToGlobal(p={x:l.perim*._x,y:l.perim*._y})

        if(o.hitTest(p.x, p.y, true)){

                    _root.fuel -= 5;
                    _root.points -= 1;
                    xMovement *= -1;
                    gravity *= -1;
        }

        
        ys += p.y;
        xs += p.x;
        c++;
    }
}

As you can see, it simply reverses the gravity and xmovement so that the helicopter goes away from the ground. If it moves slowly, this works brilliantly. However, if you hit it with any speed, the helicopter goes right through. I know why this is, I just cant fix it :frowning:

Can anyone suggest a better method?

I made a platform game as a final year project at uni… The way I did it was, calculate the ySpeed, and then:


groundHit=false;
for i=Math.round(yPosition);i<=yPosition+Math.round(ySpeed);i++
if(ground_collision(xPosition,i))
{
yPosition=i;
groundHit=true;
break;
}
if(!groundHit)
yPosition=yPosition+ySpeed;

No idea if an approach like this is applicable to flash at all? (my game was written with DirectX and C++). Another approach could be to simply stop ground collisions from happening if the sprite is heading upwards?