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:
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
Can anyone suggest a better method?