Your question is still missing the physics of your jumps. Does player's avatar accelerate when in air? Do jump physics simulate gravity well? That is the avatar's initial Vy is decelerated by 9.81 m/s every second? Still, I will present you a way how easily solve this mathematic problem.
- Let's start with representing our problem. In this case we can do this in 2D!
- Now let's assume a few things:
- we're using real physics (considering gravity, but not considering air friction etc.)
- you can still steer while in air, and therefore, you can easily avoid such situation:
- this means we should only care about being near enough to be able to jump onto a platform; we want to find an outermost distance from our target, that we can jump through to it.
- Let's analyze what happens, when we jump:
- we get initial speed Vy
- gravity makes this speed decrease by g m/s every second
- at some moment we reach the highest point and start to fall
- speed increases by g m/s until we fall on something
- all this time we're moving 'forward' by our initial velocity Vx
- moreover, all this time we're accelerating (because if we want to reach the platform from the furthest place possible, we need to hold UP key), increasing our Vx
- what we want to know is, how long have we been in air, and therefore, how much could we travel.
- Time of the jump
- here's a nice article about jump math: [How to Calculate the Jump Height From Acceleration
- time to reach top of our jump is: t = Vy/g (it's obvious, we need to lose our vertical speed completely)
- height of our jump is: h = Vyt + (gt²)/2
- formula for time we will fall from there to the platform is: where d is
h - platform.height
(taken from Wikipedia:Equations for a falling body)
- sum both t, and we get a time of our jump.
- Now we need to know how far the player will move during the jump. If he doesn't accelerate, this will be
distance = Vx*t
, but he does. So there's formula for that too: d = Vt + (1/2)at²
- We found the max distance of the jump! All you need to do is make a circle with center in point you want to reach and radius of the distance calculated, and then find your way to the circle (if you're not inside it already).
- Obviously, wherever you are, if there are no obstacles, shortest way to the circle is a line between you and center of the circle, and you need to travel distance-circle_radius to reach it.
Read more: How to Calculate the Jump Height From Acceleration | eHow.com http://www.ehow.com/how_8771263_calculate-jump-height-acceleration.html#ixzz27zGYWnD6
]3