• Advertisement
Sign in to follow this  

timing a jump - solved

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement