Archived

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

CannoN346

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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Did it! s_cloudx, i used a method similar to yours and i got my skeleton jumping. But after each jump, the jump would be shorter. It was the velocity that was causing this, because when the skeleton fell the velocity would be added to the gravity, so i simply reset the velocity everytime the skeleton hit the ground, as suggested by Brandisco. Anyways, thanks to everyone that replied.

Share this post


Link to post
Share on other sites