# Platformer/Realistic Physics

**URL:** https://forum.kirupa.com/t/platformer-realistic-physics/204721
**Category:** programming
**Created:** [October 23, 2006, 12:26am UTC](https://forum.kirupa.com/t/platformer-realistic-physics/204721 "2006-10-23T00:26:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Holmesc](https://avatars.discourse-cdn.com/v4/letter/h/9f8e36/32.png) [@Holmesc](https://forum.kirupa.com/u/Holmesc)
#### Post date: [October 23, 2006, 12:26am UTC](https://forum.kirupa.com/t/platformer-realistic-physics/204721/1 "2006-10-23T00:26:38Z")

</div>

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:

```auto
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:

```auto
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:

```auto
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](http://img350.imageshack.us/my.php?image=platformertestsub8.swf)  
Thank you for your help!

---

<div class="post-metadata">

### Author: ![Joppe](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@Joppe](https://forum.kirupa.com/u/Joppe)
#### Post date: [October 23, 2006, 2:20pm UTC](https://forum.kirupa.com/t/platformer-realistic-physics/204721/2 "2006-10-23T14:20:44Z")

</div>

[quote=Holmesc;1983371]Platform Code:

```auto
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]

```auto

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
}}

```

---

<div class="post-metadata">

### Author: ![Holmesc](https://avatars.discourse-cdn.com/v4/letter/h/9f8e36/32.png) [@Holmesc](https://forum.kirupa.com/u/Holmesc)
#### Post date: [October 24, 2006, 11:58pm UTC](https://forum.kirupa.com/t/platformer-realistic-physics/204721/3 "2006-10-24T23:58:09Z")

</div>

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!
