Hey all!
My character gets stuck in the ground with the hitTest() function.
What I’m trying to accomplish is to make him walk smoothly to the ground.
I’ve attached the swf if you want to take a look. Otherwise, this is the code:
onClipEvent(load) {
setGravity = 0.5;
gravity = setGravity;
}
onClipEvent(enterFrame) {
groundhit = _root.hill.hitTest(_x, _y, true);
if (!groundhit) {
gravity += setGravity;
_y += gravity;
} else {
_y -= gravity;
gravity = setGravity;
}
// KEYS
if (Key.isDown(Key.RIGHT)) {
_x += 2;
}
if (Key.isDown(Key.LEFT)) {
_x -= 2;
}
if (Key.isDown(Key.UP) || Key.isDown(Key.SPACE)) {
gravity = -10;
}
}
Thanks a lot in advance!