Jumping

[font=Courier New][color=black][font=‘Courier New’]Hey I was wondering if someone would be so kind as to explain the jumping code for a side scroller game because no one seems to want to explain it they just want to have me copy and paste, where’s the fun in that? Someone Please help me I have been messing with it for a couple days now and I can’t figure it out. So I was hoping that one of you fine people could enlighten me.[/font][/color][color=black][font=Arial]<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>[/font][/color]

[/font]

Here Ya Go!

onClipEvent (load) { 
//When the clip loads
grav_y = 0;
//Gravity on the y axis is zero, this is just a made up variable
jumping = false;
// The mc is not jumping
}
onClipEvent (enterFrame) {
//At any point with the MC
if (Key.isDown(Key.SPACE) && !jumping) {
//If spacebar is pressed and jumping is false so you can't jump numerous times in mid-air
grav_y = 15;
//Set gravity to 15, so he can jump
jumping = true;
//Set Jumping to true
}
if (jumping == true) {
//when jumping is true
grav_y -= 1;
//Starts falling to the ground
if (grav_y<=-7.5) {
grav_y = -7.5;
//If gravity is less than -7.5, gravity equals -7.5 ensures it can't go lower than that
}
this._y -= grav_y;
//Use of the gravity variable to drop the character to the ground
}
if (_root.ground.hitTest(this._x, this._y+45, true)) {
//If the character hits the ground 45 pixels above it
grav_y = 0;

jumping = false;
//Gravity is zero so stop jumping
}
}

Thanks a lot guys now i see why this is such a great place.

Cool! I made this place a great place :ne: :snug: