Hey,
I’ve followed a tutorial for adding slopes to a platformer and it works quite well except for 1 thing.
The hero goes up on the slope alright but when he goes down on the slope he kind of bounces down, it stops the hero from going to his walking frame and he can’t jump while moving down that slope.
Here is the code. Please help me make it so that the hero moves as smoothly down the slope as he does up it.
onClipEvent (load) {
grav = 0;
// sets falling speed
speed = 5;
// sets movement speed
jumpHeight = 10;
// sets height that you can jump
scale = _xscale;
// sets size
slowfall = .8;
// sets glide
}
onClipEvent (enterFrame) {
// happens every frame
grav++;
// makes you fall faster
_y += grav;
// makes your _y go up by the varaible grav
while (_root.ground.hitTest(_x, _y, true)) {
// when this is touching the ground
_y--;
// makes the y keep on going up, this enables slopes
grav = 0;
// make it so you dont fall
}
if (Key.isDown(68)) {
// when the d key is down
_x += speed;
// makes the x go up by the speed
_xscale = scale;
// makes it face right
if (_root.ground.hitTest(_x, _y+3, true)) {
// if it is touching the ground
this.gotoAndStop(10);
// goes to frame 1
} else {
// otherwise
this.gotoAndStop(1);
// stops at frame 2
}
} else if (Key.isDown(65)) {
// if that isnt happening and the a key is pressed
_x -= speed;
// makes the x go gown by the speed
_xscale = -scale;
// makes it face left
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(10);
} else {
this.gotoAndStop(1);
}
// see other code for movign right
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79)) {
// if this is touching the ground and o isnt pressed
this.gotoAndStop(3);
// stops at frame 3
}
}
if (Key.isDown(83)) {
// if the s key is down
grav *= slowfall;
// slows down the gravity by multiplying it by the slowfall varialbe
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68)) {
// if 0 is down, and a s d w arent
this.gotoAndStop(4);
// goes to frame 4
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
// if w is pressed and it is touching the ground
grav = -jumpHeight;
// makes gravity negative jumpheight, causes jump
_y -= 4;
// makes the y go up by 3
this.gotoAndStop(2);
// stops on frame 2
}
if (_root.ground.hitTest(_x+(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2), _y-((_height/6)*4), true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2), _y-((_height/6)*4), true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height, true)) {
grav = 2;
}
// these all check for 2 points along the sides and top, to see if it is hitting a wall
}