# timing a jump - solved

## Recommended Posts

I'm making a simple 2d game and want to time my jumps so that in .75 seconds he reaches the peak of his jump and in another .75 seconds he is back on the ground. The way I do it right now is all frame independent but I have no control over how long he is in the air for. Here's what I have
	float jumpDistance = 32.0f;

if (bjump == rising)
{
distanceJumped += jumpDistance*elapsedtime;
movementValue = jumpDistance*elapsedtime;

if (distanceJumped >= desiredDistance)
{
movementValue -= distanceJumped - jumpDistance;
distanceJumped = 32;
bjump = falling;
}
}
else
{
distanceJumped -= jumpDistance*elapsedtime;
movementValue = -jumpDistance*elapsedtime;

if (distanceJumped <= 0)
{
movementValue -= distanceJumped;
jumpingFlag = 0;
bjump = rising;
distanceJumped = 0;
isJumping = 0;
}
}

yPos += movementValue;


What would you reccommend that I do to make this jump timed? [Edited by - gellin on October 22, 2005 5:34:24 PM]

##### Share on other sites
Since you want the jumper to reach desiredDistance (which I would rename to halfDesiredDistance) in 0.75 seconds, you need to set jumpDistance (which I would rename to jumpVelocity) to desiredDistance / 0.75 (or 750 if your values are in ms), rather than setting it to a constant (32).

##### Share on other sites
Nevermind. It turns out I already had some timer in there. I haven't worked on this in a week and forgot I put it in already. Thanks anyways.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628354
• Total Posts
2982236

• 10
• 9
• 11
• 24
• 11