jumping

Started by
7 comments, last by superpig 19 years, 1 month ago
does anybody know a good equation for jumping?
Advertisement
When you start the jump, call this function:

void Jump(){    Player.yspeed = 10;    Player.jumping = true;}


and when the player is in the middle of a jump:

void HandleJump(){    Player.y -= Player.yspeed;    Player.yspeed--;    // Check collision.}







-----------------------------Play Stompy's Revenge! Now!
well This might sound easy but have you thought a simple quadratic formula?

y=-x^2+3x for instance but instead of X make it time, and after 3 units you'll be at the height of your jump, and just have it so when y=0 and Time is not =0 he will have landed.

Though I'd check that, that was off the top of my head (I unfortunatly don't have graphing software on my computer right now) . Of course that uses Absolute positions. I'm sure you can tweak something like that for gravity for your world.

That makes a simple Mario style Leap.

Or are we speaking of a different sort of jumping? A little more information might be helpful here.
sorry for the lack of info, and thanks for trying to help. i have a first person game, and i can't get a jumping formula down. Stompy9999, i don't really get where the player and speed stuff is. i was thinking about something using sine or cosine, but i don't know of any formulas that will have me jump, and while im getting to the top of my jump, start to slow down, then as its going down, start to slow down.
If it's a first person 3d game, there is no need to use trigonomotry to jump. All you need to do is increase along the y-axis while jumping and stop jumping when the player collides with something.
-----------------------------Play Stompy's Revenge! Now!
Quote:sorry for the lack of info, and thanks for trying to help. i have a first person game, and i can't get a jumping formula down. Stompy9999, i don't really get where the player and speed stuff is. i was thinking about something using sine or cosine, but i don't know of any formulas that will have me jump, and while im getting to the top of my jump, start to slow down, then as its going down, start to slow down.

Stompy9999's solution will do that. When the character begins its jump, it will have a certain vertical speed. Over time, the vertical speed decreases, and at some point it will become zero. That's the top of the jump. The vertical speed continues to decrease, becoming negative (i.e. downward). Eventually he hits the ground and its all over.
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter
heres a time based way to jump

x_t = x_0 + v_0*t + 0.5*a_0*t*t
v_t = v_0 + a_0*t

x_0 is the current height
x_t is the new height after time t
v_0 is the current velocity
v_t is the new velocity after time t
a_0 is the acceleration (gravity)
t is how mush time passed

to jump set the velocity (v_0) to some number that is opposite of the acceleration (like v_0 = -10 and a_0 = 15)
Quote:Original post by iedoc
sorry for the lack of info, and thanks for trying to help. i have a first person game, and i can't get a jumping formula down. Stompy9999, i don't really get where the player and speed stuff is. i was thinking about something using sine or cosine, but i don't know of any formulas that will have me jump, and while im getting to the top of my jump, start to slow down, then as its going down, start to slow down.


Here's a simple jump using sine that jumps to a maximum of J pixels. replace i with your jumping counter.

PI=3.14159265
for i=0 to 1 step 0.1
jump=(sin(i*PI)*J)
next
The most flexible way to handle jumping comes in two parts:

1) Gravity (i.e. falling) - this'll account for running off the side of platforms and stuff like that too.
2) Upthrust - this'll throw your guy upwards when the player hits 'jump.'

Something you'll need to know for both of those is whether or not the player is 'on the ground' (so you can stop them hitting jump when they're already in midair, and so you know when to stop falling). There are various ways of doing it; one approach I might take is to sample a point X units below the player's feet, and find out whether it's floor or not.

Once you've got that, you can implement gravity:
void Player::ApplyGravity(){ if(!IsOnFloor()) {  velocity.y += GRAVITY; } else {  velocity.y = max(velocity.y, 0); }}void Player::Update(){ position += velocity;}


And when you want to jump:

void Player::Jump(){ velocity.y = JUMP_SPEED;}


You'd set JUMP_SPEED and GRAVITY to constants that make sense for your player - they'd have opposite signs, of course (because they're going in opposite directions).

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement