# Jerky Jumping

**URL:** <https://forum.kirupa.com/t/jerky-jumping/42077>\
**Category:** programming\
**Created:** [February 4, 2004, 10:35pm UTC](https://forum.kirupa.com/t/jerky-jumping/42077 "2004-02-04T22:35:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![InsaneMonk](https://avatars.discourse-cdn.com/v4/letter/i/ce7236/32.png) [@InsaneMonk](https://forum.kirupa.com/u/InsaneMonk)\
**Post date:** [February 4, 2004, 10:35pm UTC](https://forum.kirupa.com/t/jerky-jumping/42077/1 "2004-02-04T22:35:10Z")

</div>

I’m currently in the middle of a game project and came across a problem. Whenever I jump in the game(please try to understand me), the character jumps normally until he hits the floor. When that happens (at the time, he is obviously lower than the floor), he jerks upward to the exact postition of the floor. I know why this happens (the computer checks if his y postion is LOWER than the floor), but I don’t know how to fix it. Please help! Here is the code:  
[AS]if (pc.\_y\<floor && !jumping) {  
pc.\_y += yvel;  
}  
if (pc.\_y\>floor) {  
pc.\_y = floor;  
yvel = 15;  
jumping = false;  
}  
if (jumping == true) {  
pc.\_y -= yvel;  
yvel -= 2;  
}  
if (Key.isDown(Key.UP) && !jumping) {  
jumping = true;  
}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 5, 2004, 2:08am UTC](https://forum.kirupa.com/t/jerky-jumping/42077/2 "2004-02-05T02:08:12Z")

</div>

what i would do is change the operator \< to \<=

if (pc.\_y\<=floor && !jumping) {  
pc.\_y += yvel;  
}  
if (pc.\_y\>floor) {  
pc.\_y = floor;  
yvel = 15;  
jumping = false;  
}  
if (jumping == true) {  
pc.\_y -= yvel;  
yvel -= 2;  
}  
if (Key.isDown(Key.UP) && !jumping) {  
jumping = true;  
}

let me know if it helps :!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 5, 2004, 10:30pm UTC](https://forum.kirupa.com/t/jerky-jumping/42077/3 "2004-02-05T22:30:24Z")

</div>

That won’t work… because the code sets his y postion straight back to “floor.” And if you were checking if he was equal with the floor, he would not be able to jump. ☹ Sen! I need you!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 7:41am UTC](https://forum.kirupa.com/t/jerky-jumping/42077/4 "2004-02-06T07:41:33Z")

</div>

[AS]  
if (pc.\_y\>floor) {  
pc.\_y = floor;  
yvel = 15;  
jumping = false;  
}  
[/AS]  
Here it looks like your trying to stop the jumping… but why would the movie clip need a velocity if jumping is false…  
I could be wrong but its worth a shot  
[AS]  
if (pc.\_y\>floor) {  
pc.\_y = floor;  
yvel = 0;  
jumping = false;  
}  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 9:44am UTC](https://forum.kirupa.com/t/jerky-jumping/42077/5 "2004-02-06T09:44:48Z")

</div>

Hoi

this solves your prob

```auto

if (pc._y<floor && !jumping) {
        pc._y += yvel;
}
if (jumping == true) {
        pc._y -= yvel;
        yvel -= 2;
}
// moved the if() down
if (pc._y>floor) {
        pc._y = floor;
        yvel = 15;
        jumping = false;
}
if (Key.isDown(Key.UP) && !jumping) {
        jumping = true;
}

```

flash reads up to down 🙂  
a good tip when trying solve prob’s like this is to look at the code and do very thing step by step in you mind. And when testing thing you should all ways have it **after** a change has been made 😃

Eidt: fixing typ0 😊

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 9:53am UTC](https://forum.kirupa.com/t/jerky-jumping/42077/6 "2004-02-06T09:53:14Z")

</div>

Ahhhh nicley spotted!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 12:29pm UTC](https://forum.kirupa.com/t/jerky-jumping/42077/7 "2004-02-06T12:29:03Z")

</div>

thanx 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 8, 2004, 5:36pm UTC](https://forum.kirupa.com/t/jerky-jumping/42077/8 "2004-02-08T17:36:32Z")

</div>

hey! thanx alot!
