Forums

ForumsProgramming Forum

Platformer game - walking on slopes.

Posted Feb 28, '12 at 1:34pm

HappyBlack

HappyBlack

2 posts

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. (:

 

Posted Mar 2, '12 at 8:04am

HappyBlack

HappyBlack

2 posts

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..
 

Posted Mar 5, '12 at 5:48pm

fiester

fiester

19 posts

Make the gravity a higher number

 

Posted Sep 6, '12 at 4:48pm

Guddis

Guddis

1 post

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

 
Reply to Platformer game - walking on slopes.

You must be logged in to post a reply!