PDA

View Full Version : Character Jumping Help


DemonicEZZA
07-07-2008, 11:03 AM
I Want My Character To Be Able To Jump But
I Don't Want Him To Be Able To Fly Or Double
Jump Here Is My Current Code:

onClipEvent (load) {
speed=7;
isJumping = false;
jumpSpeed = 0;
startY = _y;
}
onClipEvent (enterFrame) {
if(isJumping) {
_y += jumpSpeed;
jumpSpeed+=1;
if(_y>startY) {
_y = startY;
isJumping=false;

}
}
if (Key.isDown(Key.UP)) {
gotoAndStop("jump")
isJumping = true;
jumpSpeed = -10;
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop("runr");
this._x += 25;
}
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("runl");
this._x -= 25;
}
if (Key.isDown(Key.DOWN)) {
this.gotoAndStop("duck");
}
}
onClipEvent (keyUp) {
this.gotoAndStop("stop");
}

GMaker0507
07-07-2008, 03:10 PM
based on your code:

if (Key.isDown(Key.UP)&&isJumping==false) {
gotoAndStop("jump")
isJumping = true;
jumpSpeed = -10;
}

The rest seems fine.. if your working with a perfectly flat level. What i mean is:

if(_y>startY) {
_y = startY;
isJumping=false;
}

That should work fine.But what happens if you have platforms or something that are above your startY?

a simple, basic solution is to create an mc that would represent your ground, like GroundMc then test if it hits your feetX and feetY via the hitTest function

If you dont know about it, search flash help docs, they give a good description

the feetX and feetY is just some made up terms for where your feet would be

DemonicEZZA
07-07-2008, 10:00 PM
Now When He Jumps He Can Still Fly And Double Jump But Now He Doesn't Come Back Down

GMaker0507
07-08-2008, 01:02 AM
are you sure, i just tried it out quickly with the code i posted and it worked fine

onClipEvent (load) {
speed = 7;
isJumping = false;
jumpSpeed = 0;
startY = _y;
}
onClipEvent (enterFrame) {
if (isJumping) {
_y += jumpSpeed;
jumpSpeed += 1;
if (_y > startY) {
_y = startY;
isJumping = false;

}
}
if (Key.isDown (Key.UP) && isJumping == false) {
gotoAndStop ("jump");
isJumping = true;
jumpSpeed = -10;
}
if (Key.isDown (Key.RIGHT)) {
this.gotoAndStop ("runr");
this._x += 25;
}
if (Key.isDown (Key.LEFT)) {
this.gotoAndStop ("runl");
this._x -= 25;
}
if (Key.isDown (Key.DOWN)) {
this.gotoAndStop ("duck");
}
}
onClipEvent (keyUp) {
this.gotoAndStop ("stop");
}