jumping
When you start the jump, call this function:
and when the player is in the middle of a jump:
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.}
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.
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.
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.
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)
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:
And when you want to jump:
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement