# Platformer/Realistic Physics

Hello! I recently have been working on a platformer game. It is successful, but there is one part of it that does not work. The element that is troubling me is jumping. Before I get into asking questions, I’d like to state that I HAVE read nathan99’s tutorial, downloaded his .fla, and gotten thouroughly confused. Now, back to jumping. I have experimented with my character’s jumping somewhat, and when he jumps he has some realism in his hopping about. As he gets higher in the air, he slows, then begins to fall. This all works nicely, except that when he jumps to a higher platform and walks off the side of it, he doesn’t fall, he floats through the air. Here’s all the code, as it may help:
Root Code:

var jumping:Boolean = false;
var falling:Boolean = false;
var jump:Number = 12;
var jumpGo:Boolean = true;
onEnterFrame = function () {
if (Key.isDown(Key.UP) && jumping == false && jumpGo == true) {
jumping = true;
jumpGo = false;
} else if (jumping == true && jump>=1) {
jump -= 1;
} else if (jump<=1) {
jump = 12;
jumping = false;
falling = true;
}
};

Character Code:

onClipEvent (enterFrame) {
//Jumping
if (_root.jumping == true) {
this._y -= _root.jump;
this.gotoAndStop("jump");
if (Key.isDown(Key.RIGHT)) {
this._x += 2;
this._xscale = 100;
} else if (Key.isDown(Key.LEFT)) {
this._x -= 2;
this._xscale = -100;
}
//Falling
} else if (_root.falling == true) {
this._y += 7;
if (Key.isDown(Key.RIGHT)) {
this._x += 4;
this._xscale = 100;
} else if (Key.isDown(Key.LEFT)) {
this._x -= 4;
this._xscale = -100;
}
this.gotoAndStop("fall");
//Walking
} else if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop("walk");
this._x += 5;
this._xscale = 100;
} else if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("walk");
this._x -= 5;
this._xscale = -100;
} else {
this.gotoAndStop("stand");
}
}

Platform Code:

onClipEvent (enterFrame) {
if (_root.char.hitTest(this)) {
if (_root.falling == true) {
_root.falling = false;
_root.jump = 12;
_root.jumping = false;
_root.jumpGo = true;
_root.char.gotoAndStop("stand");
}
}

}
Also, I have another question. Is there a way to make the character only land on top of platforms, not in the sides of them? Essentially, how can I hitTest the _x and _y of the character to the whole of the platform?
I know that it would have been easier to post the .fla file, but the file was too large. However, you can access the .swf at http://img350.imageshack.us/my.php?image=platformertestsub8.swf

[quote=Holmesc;1983371]Platform Code:

onClipEvent (enterFrame) {
if (_root.char.hitTest(this)) {
if (_root.falling == true) {
_root.falling = false;
_root.jump = 12;
_root.jumping = false;
_root.jumpGo = true;
_root.char.gotoAndStop("stand");
}
}

[/quote]

onClipEvent (enterFrame) {
if (_root.char.hitTest(this)) {
if (_root.falling == true) {
_root.falling = false;
_root.jump = 12;
_root.jumping = false;
_root.jumpGo = true;
_root.char.gotoAndStop("stand");
}
else{
_root.falling == true
}}

Well, that script would technically work, but I have more than one platform. The problem presented by this is that if the player is not touching ALL of the platforms, falling = true. I’ve remedied this by adding a variable that detects if the player is touching the ground though, so it works now. Thank you!