hello there,
I wrote a gravity script that i'm very happy with. the only problem is that if the object falls from a cretant hight, he wall fall through the ground or get stuck in the middle. this is an issue because in the game im making, i realy can have him sticking through the ground. If someone could help me to understand this, explain why it is happerning (please) and how to fix it, much would be appreciated.
this is the script. it wroks well, expet for high hights
onClipEvent (load) {
fallSpeed = .2;
maxFallSpeed =10;
grav_y = 0;
fall = true;
}
//gravity
onClipEvent (enterFrame) {
if (grav_y>MaxFallSpeed) {
grav_y -=1;
}
if (fall == false) {
grav_y = 0;
}
if (fall == true) {
grav_y += fallSpeed;
if (grav_y>0) {
grav_y += fallSpeed;
}
}
if (_root.ground.hitTest(_x, _y, true) == false) {
fall = true;
}
if (_root.ground.hitTest(_x, _y, true)) {
fall = false;
}
this._y += grav_y;
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(_x, _y, true)) {
this._y -=grav_y;
grav_y = 0;
}
}