• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Implementing Jumping in my 2d Side-scroller

## Recommended Posts

Ok, im surrently working on a scroller. Im trying to implement jumping using the principles from the physics chapter from TOTWGPG. I can make the skelaton move up but i need to make it so that he can only jump while on the ground. Heres my code
  // model gravity skelaton.y+=skelaton.yv; skelaton.yv+=gravity; if ((keyboard_state[DIK_SPACE]) && (deb_key==0)) { skelaton.y-=skelaton.yv; deb_key=1; } if ((keyboard_state[DIK_SPACE]) && (deb_key==1)) skelaton.y+=skelaton.yv; 
Using this he cant jump at all. if i add an "else" it can jump even while in the air. So, i added this code to the collision function...
  // collision test while(Collision_Test(skelaton.x,skelaton.y,skelaton.width,skelaton.height, 0,384,SCREEN_WIDTH*2,SCREEN_HEIGHT)) { skelaton.y-=1; deb_key=0; } 
This did nothing. And lastly i tried this block of code and this didnt work.
  if (skelaton.y <= 383) deb_key=0; else if (skelaton.y > 383) deb_key=1; 
I had similar problems like this before and this technique worked. Now im stuck. Any suggestions??

##### Share on other sites
You could set a flag that indicates the character is allowed to jump. Set it to false when they jump, and back to true when they land.

(P.S. Did you mean skeleton?)

##### Share on other sites
bool bJumping = false;if(jump_key){  if(!bJumping)  {    // jump routine  }}

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

##### Share on other sites
I didn''t look at all your code but I would quickly suggest that since .yv is always decreasing while the person is jumping somewhere you must reset .yv to an initial start value before a jump. So you could just check if .yv == the inital start value then allow the jump. If not, then don''t.

##### Share on other sites
Ok, thank you, i will try those methods. LoL, yes magmai, it should be skeleton.

##### Share on other sites
The way I did my jump is here:

http://www.gamedev.net/community/forums/topic.asp?topic_id=78723

EDIT:
oops. sorry. I didn't read the topic well (still sleepy from last night). anyways, what I just sent is how i implemented my jump not on landing. bad s_cloudx, bad.

Edited by - s_cloudx on February 17, 2002 6:39:24 PM