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

Started by
4 comments, last by Stompy9999 19 years, 2 months ago
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.
Mark St. Jean - OwnerWastedInkVwmaggotwV@Yahoo.com
Advertisement
Correct me if I'm wrong but isn't that equivalent to
void Jump(){    p1.y_vel = 49;    p1.y_pos -= 50;}
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.
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
MSN: stupidbackup@hotmail.com (not actual e-mail)ICQ: 26469254(my site)
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::)
Mark St. Jean - OwnerWastedInkVwmaggotwV@Yahoo.com
Quote:Thanks for all of your help, now feed me the good ratings :) j/k (please? ::blushes::)


That's not a wise idea
-----------------------------Play Stompy's Revenge! Now!

This topic is closed to new replies.

Advertisement