Forums → Programming Forum → Platformer game - walking on slopes.
3 | 5825 |
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. (:
- 3 Replies
Fixed.
I didn't notice that I wrote
falling = true;instead of
_root.hero.falling = true;.
But now the hero bounces all the time when he touches the ground. Is there way to fix it? Don't want to get rid with while() thing, because without it the hero walks into the slope, not along it..
Try using something to define velocity, whether it's higer or lower than 0. (if(velocity < 0) { (etc, you know the drill)), and stick it in the OnClipEvent for the state ("running" apparantly) you want it in.
I might be to late though since there's been little avtivity since mars on this post.
Hope you fixed it, would be a shame if such a petty problem got in the way of a great consept.
I'm not that good with AS3, keep that in mind
You must be logged in to post a reply!