# How long will it take to jump from point A to point B?

I need to know how long it takes to jump from one point to another. Because if the jump time takes for example 2.0f(float jumptime = 2.0f), a jump animation is played during a time interval of exactly 2.0f. The difficult thing is, I need to know the jump time before the jump was executed.

Is it possible to calculate that right before the jump is executed or is it impossible to calculate that?

I use the following formula to let an object(ball) jump from one platform to another platform:

impulse = Vector2(distance.x / time * mass + gravity.x / 2 * time * mass, distance.y / time * mass + gravity.y / 2 * time * mass);

Description of the jump

Update:

My calculations:

float gravity = 3, timetopeak, timetoground, totaljumptime, waytothetop, waytotheground;

timetopeak = jumpForce.Y / -gravity;
waytothetop = (float)(0*timetopeak + 0.5*-gravity*timetopeak*timetopeak);
waytotheground = Ball.Position.Y + waytothetop - (PlatformB.Position.Y - PlatformBHeight / 2.0f - BallHeight / 2.0f);
timetoground = (float)(Math.Sqrt(2 * waytotheground / -gravity));
totaljumptime = timetopeak + timetoground;
Ball.ApplyLinearImpulse(ref jumpForce);
//I divide the totaljumptime because the animation has 5 frames.
BallAnimation = new Animation(totaljumptime/5, 32, 32, Animation.Sequences.forwards, 0, 5, false, true);


Are my calculations correct? Because the totaljumptime is very small and my animation runs much too fast.

• Do you know the distance of the jump and the speed you'll be traveling? Jan 27, 2014 at 23:24
• If you know the velocity on x - Axis and the distance, you know the time. You just divide the distance by the velocity. Jan 28, 2014 at 0:40
• I know the distance because I know the coordinates of platformA and platformB. In addition, I know the velocity(X,Y). I thought it wouldn't be possible to divide the distance by the velocity because I use a gravity. Jan 28, 2014 at 21:43

Sure you can know the time, as long as you know the initial velocity, the acceleration (gravity), and the difference in height between point A and point B (this is crucial: if you don't know where the ball is landing, naturally you won't know the duration of the jump).

If the ball has an upward velocity of v, and it accelerates downward at a rate a, then the time taken for it to reach the peak of the jump is simply t = v/a. To know how far up it travelled, this equation comes in handy:

s = ut + 0.5at^2

// s = distance
// u = initial velocity
// a = acceleration
// t = time


Plug in our values (v for u, and make sure a is negative), and then we move on to the next step. You know how long it took to get to the peak of the jump. How about down? Well, if it's landing at the same height it started, then the duration is the same. t * 2. Otherwise, you need to find the distance it still has to travel:

initial height + height travelled upwards - final height


(s = ut + 0.5at^2 is what we used to get the distance travelled upwards)

Once we have that, use the same formula again, this time rearranging to solve for t:

s = ut + 0.5at^2
// since the initial velocity is 0, it becomes:
s = 0.5at^2
2s = at^2
root(2s/a) = ±t
t = ±root(2s/a) // Note, we want the positive answer


And there you go, you got the time for the ball to drop from the peak of its height. Add that to the time it took to get to the peak of the jump, and you've got the overall time.

If that wasn't well illustrated enough, look up projectile motion.

(Yes, the above could be simplified into a single equation, but, I find that it's more intuitive to understand as I've illustrated it above.)

• Will the mass of the ball change something on the formula or can I use this formula in every case? Jan 28, 2014 at 0:37
• Mass does not affect the rate of acceleration due to gravity, so it works for all cases (unless you want to take into account air resistance). en.wikipedia.org/wiki/… Jan 28, 2014 at 0:42
• I have a little problem. The totaljumptime is very small and therefore the animation runs much too fast. Is something wrong with my calculations(I updated my question with new code) or why is the totaljumptime very small? Jan 28, 2014 at 21:37