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;
timing a jump - solved
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
What would you reccommend that I do to make this jump timed?
[Edited by - gellin on October 22, 2005 5:34:24 PM]
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement