Hello. (:
I'm working on a platform game and some of things don't work as I would like to.
Actually these are slopes. Hate them.
I'm using AS2. Would like to save having not-only-one ground feature.
If the hero goes up, it isn't a problem, it's ok, everything works.
But if he tries to go down..
He just doesn't want to fall. Goes on the same height as he started.
If he tries to jump, he falls correctly, landing on the ground.
Here is code for the ground:
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.hero._x, _root.hero._y, true)) {
_root.hero.falling = false;
_root.hero.velocity = 0;
} else {
falling = true;
}
while (this.hitTest(_root.hero._x, _root.hero._y, true)) {
_root.hero._y--;
}
}
For the hero:
Code:
onClipEvent (load) {
gravity = 0.3;
velocity = 0;
falling = true;
running = false;
stop();
speed = 2;
talk = false;
}
onClipEvent (enterFrame) {
if (falling == true) {
this.gotoAndStop(13);
velocity += gravity;
_y += velocity;
}
if (Key.isDown(Key.RIGHT) && !talk) {
gotoAndStop(12);
this._xscale = 100;
_x += speed;
running = true;
} else if (Key.isDown(Key.LEFT) && !talk) {
gotoAndStop(12);
this._xscale = -100;
_x -= speed;
running = true;
} else {
if (!falling) {
running = false;
this.gotoAndStop(11);
}
}
if (Key.isDown(Key.UP) && !talk) {
if (falling == false) {
velocity -= 4.5;
falling = true;
}
}
if(falling && running){
this.gotoAndStop(13);
}
}
Thanks for any help. (: