Ok so I programming a character to when they press the UP key they jump and then gravity takes place. The only problem I have is whenever I force the player above the ground the gravity keeps taking place so the player jigs up and down constantly. How can I fix this? Here is my current code
Note that this code is on my player (named char) and is interacting with a dynamic floor movieclip called “ground”
onClipEvent(load){
jumping = false;
gravitySpeed = 3;
}
onClipEvent(enterFrame){
walkSpeed = 5;
if(Key.isDown(Key.LEFT)){
this._x -= walkSpeed;
this._xscale = -100;
}
if(Key.isDown(Key.RIGHT)){
this._x += walkSpeed;
this._xscale = 100;
}
touchingGround = _root.ground.hitTest(this._x, this._y, true);
if(!touchingGround && !jumping){
this._y += gravitySpeed;
}
if(Key.isDown(Key.UP) && !jumping){
jumping = true;
gravitySpeed = -15;
}
if(jumping){
if(gravitySpeed < 15){
gravitySpeed += 1;
}
this._y += gravitySpeed;
if(touchingGround){
jumping = false;
}
}
//This is the part of the code that puts the player above the ground
if(_root.ground.hitTest(this._x, this._y + 1)){
this._y -= 1;
}
}