Jump to content

Calculate jump distance?


fbrcc
 Share

Recommended Posts

Hello Forum,

 

I'm making a platform game with randomly created platforms. I'd like to know if there's a way to calculate the XY distance a body with a positive X velocity can jump taking into account the X velocity, the gravity and the negative Y velocity I used for the jump. This is to be able to create reachable platforms and to be able to change one value and calculate the rest accordingly. 

 

Thanks in advance.

Link to comment
Share on other sites

Hi, you can split this into vertical and horizontal move. First vertical:

 

total distance traveled is:

s = s0 + v * t + 1/2 * g * t^2

where:

  s0 = initial distance (zero in our case),

  v = velocity,

  t = time,

  g = gravity (opposite sign to velocity)

 

You have gravity and you know velocity (jump initial speed). s0 is zero and your normal jump stars and ends on floor so total distance traveled vertically is 0 too. Question is how long it takes from start to land (t). Let us say that jump velocity is -50 and gravity is 10 then:

  0 = 0 + (-50) * t + 1/2 * 10 * t^2
50t = 5 * t^2
 50 = 5t
 10 = t

 With given parameters it takes 10 seconds from jump start to land. As you know x velocity of your character you can calculate x distance it traveled during jump like: x_vel * t, where t is time you just calculated.

 

 If you get first derivation from above function, you can also calculate, how high along y the jump is. First get time in which maximum height is reached:

 0 = v + 2 * 1/2 * g * t
 0 = -50 + 1 * 10 * t
50 = 10 * t
 5 = t

 Now, put t = 5 into very first formula:

s = 0 + (-50) * 5 + 1/2 * 10 * 5^2 = -250 + 125 = -125

It is negative, as your jump speed is negative too and gravity is positive (as screen coords are flipped ... 0 up)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...