timing a jump - solved

Started by
1 comment, last by gellin 18 years, 5 months ago
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]
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).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.

This topic is closed to new replies.

Advertisement