Public Group

#### Archived

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

# jumping up and down...

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

## Recommended Posts

hi... before you kindly reffer me to google, know that i''ve been googling then up for about two days now, and needless to say, i''ve not had much success... anyhoo, about two years ago, i read this one tutorial on how to make a character jump... it had this one formula that i can''t remember, but was something like, (if jump = true) y = d/s (where y is the y coord of the character jumping, d is the distance it will jump up before it starts going down and s is the speed)... i''ve tried that in my code (i''m not sure if that''s what the formula was though), and it didn''t work. i''m trying to effectively have this block i have on the screen "jump" when i press a key, but the way i''m currently doing it (in C# builder) doesn''t look too good.... the block jumps, but it looks like it''s on space. this is what i basically did: y = block''s y coord distance = distance it''ll jump UP (equals to 5) move = amount of pixels it moves at a time (equals to 1) jump = false when i hit the jump key, "jump" is set to true... in the timer, i check to see if jump is true. is so, i''ll do this: if(jump == true) { for(int i = 0; i < distance; i++) { y += move; } for(int z = 0; z < distance; z++) { y -= move; } } any suggestoins? thanks

##### Share on other sites
You are doing too many iterations at once. Change the y value only once per timer call.

##### Share on other sites
that''s what i do... i only increase it once per call and start decreasing it when it reaches the peak...

##### Share on other sites
Your current method will look weird because it actually generates a triangular movement, not an arc which you''d expect from a jump. Instead use a constant downward acceleration from gravity and a large initial speed:
const float GRAVITY = -9.81;// Every frame: (where ''delta'' is elapsed time)if (hasPressedJump()){  jumpSpeed = 10;// some arbitrary initial speed  isJumping = true;}if (isJumping){  // Apply acceleration to current speed  jumpSpeed += GRAVITY * delta;    // Use speed to update height  characterY += jumpSpeed * delta;}

##### Share on other sites
cool! thanks a lot!!!

##### Share on other sites
quote:
Original post by OrangyTang
Your current method will look weird because it actually generates a triangular movement, not an arc

A parabola, ie -(x^2) shape, to be precise, if anyone didn''t know...

• 11
• 20
• 12
• 10
• 38
• ### Forum Statistics

• Total Topics
631400
• Total Posts
2999862
×