PDA

View Full Version : Jumping Codes and Smoothness



LordArkain
April 18th, 2007, 01:24 PM
Hi all, I have been working on custom scripts for jumping and have managed to get some that worked. They were not the greatest though when it came to style and such.:stare:
What I did in my scripts is I made variables (falling, jumping, jumpheight) and check to see if my character was hitTest with ground at the same time jumping==false; . And if he was, falling=false; That was the detection for the falling. The jumping would read if the key was down(UP) and if it was, jumping would return true. Then within the clip event I made it check to see if jumping was true, and if it was, using another if statement jumpheight would -1 untill it reached zero while the character would jump with this._y-=5; . When jumpheight reached zero it would reset to its primary value, which I defined 10 earlier in my script, and falling would return true while jumping would become false.
Pretty much its a simplified jumping script. The only thing was the character would go straight up, and then straight down and it would look very corny. My attempts to get around this and make it look smooth ended up ruing the script. :stare:
Now I use a code learned from a tutorial to make the character jump and fall. But I was wondering if anyone would mind helping me smooth out something.
Here is my file (FLA (http://www.geocities.com/foestarstorage/Files/NewSystem.fla)) <-----FLashMX 2004 (SWF (http://www.geocities.com/foestarstorage/Files/NewSystem.swf))
If you can't open the file all my codeing is within the main character. Here it is.


//defined variables on load
onClipEvent(load){
jumping = true;
jump = 0;
falling=true;
fallspeed=10;
movespeed=5;
position="right";
}
//left right movement and ending stance
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
position="right";
this.gotoAndStop("standright");
this._x+=movespeed;
}else if(Key.isDown(Key.LEFT)){
position="left";
this.gotoAndStop("standleft");
this._x-=movespeed;
}else{
if(position=="right"){
this.gotoAndStop("standright");
}else if(position=="left"){
this.gotoAndStop("standleft");
}
}
//jumping
if (Key.isDown(Key.UP) && !jumping && !falling) {
jumping = true;
}
if (jumping) {
this._y -= jump;
jump -= .5;
if (jump<0) {
falling = true;
}
if (jump<-15) {
jump = -15;
}
}
//falling
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}
if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
this._y += fallspeed;
falling=true;
}
}


Now what i'm trying to smooth out in this script is landing withing larger platforms. If I have a thick platform, the player can land within its middle rather than just land on top. This is what I am trying to smooth out. I may have a idea on how to do this, but I am still experimenting at the moment.

Joppe
April 18th, 2007, 01:37 PM
while (_root.ground.hitTest(this._x, this._y+1, true)) {
this._y--;
}
Add that :)

LordArkain
April 18th, 2007, 02:21 PM
Hmmm, that seemd to make the jump script stop working. Didn't seem to have the effect. Am I using it wrong? I placed it within the the onClipEvent handler. But it didn't seem to have the desired effect no matter where I put it. Btw, I never used while statement before. How exactly does it work? Like the else command? Or is it similar too &&?

Jiruharudo
May 4th, 2007, 03:09 AM
I think it looks pretty good. ^^

Maybe buff up the frame rate to make it less sluggish..

But good! ^^

Now go add some animations! ^_________^

..And then be forced to peer at your monitor whilst ponderig how to make a enemy script like me.. =__=;

But seriously though, keep it updated.
I'd like to see how far this'll go. ^^