# Smooth jumping... Not what you would think...

This topic is 4906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have currently tried rewritig my jumping in my 2d plat-fighter so that it uses one function instead of about three. Anyways here it is:
void Jump()
{
p1.y_vel = 50;
p1.y_pos = p1.y_pos-p1.y_vel;
p1.y_vel--;
}


What I cant figure out is how to give it a smoth jump up instead of a straight jump up 50 pixels. I am not to good at math so I think its pretty good I knew how to do that period. Anyways is there different math equasions I can use to make the character move up by say 2 pixels at a time, until it reaches a peak then stops? I have a gravity function running every frame so I dont need to worry about coming down.

##### Share on other sites
Correct me if I'm wrong but isn't that equivalent to
void Jump(){    p1.y_vel = 49;    p1.y_pos -= 50;}

##### Share on other sites
The code seems about right (i.e. physically correct) except that you shouldn't reset the velocity each frame of the animation.
void BeginJump() { y_vel = -FORCE;}void UpdateJump() { y_pos += y_vel; y_vel += GRAVITY;}
Also, to avoid jumping 50 pixels in one frame you obviously need to use a smaller initial force. Possibly even floating point or fixed point numbers.

##### Share on other sites
Your gravity function should be all you need to get it to stop
When you jump just set the velocity to 50 like you are doing, and then add the velocity to the position each frame...
If your gravity function decreases the velocity then this should get the effect you want

##### Share on other sites
Thank you all for your help. It now functions good. Im going to have to work on my gravity some other time to make that look smoother (possiably just changed jump to work backwords :) ) but other than that im done. Here check out the new code:

//Simulates a jumpvoid Startjump(){p1.y_vel = 15;p1.jump = true;p1.inair = false;}void Jump(){    p1.y_pos -= p1.y_vel;    p1.y_vel--;    if (p1.y_vel == 0)    {    p1.jump = false;    p1.inair = true;    }}//Simulates Gravityvoid Gravity(){if(map[(((p1.y_pos+spriteh)+1)/32)][(p1.x_pos/32)] != 0)p1.y_pos+=1;if(map[(((p1.y_pos+spriteh)+1)/32)][(p1.x_pos/32)] != 0)p1.y_pos+=1;if(map[(((p1.y_pos+spriteh)+1)/32)][(p1.x_pos/32)] != 0)p1.y_pos+=1;if(map[(((p1.y_pos+spriteh)+1)/32)][(p1.x_pos/32)] != 0)p1.y_pos+=1;}

Thanks for all of your help, now feed me the good ratings :) j/k (please? ::blushes::)

##### Share on other sites
Quote:
 Thanks for all of your help, now feed me the good ratings :) j/k (please? ::blushes::)

That's not a wise idea

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631714
• Total Posts
3001867
×