I would use a kinematic equation to find the time needed. Specifically, probably this one:
Code:
v[f] = v[i] + a * t
Solved for
t, that gives us:
Code:
t = (v[f] - v[i]) / a
So if the initial vertical velocity is called "yv" and the vertical downward acceleration is called "g", you might use this:
Code:
time = 2 * yv / g
Then just multiply that by the horizontal velocity to get the distance. EDIT: Or rather, divide that from the distance to get the horizontal velocity.
But if your game's acceleration is nothing more than simplistic additions to velocity variables each frame (which is what Game Maker does if I'm not mistaken), that won't actually work. In that case, the only way I can think of other than hardcoding it is to use looping to simulate the trajectory. If you do have to do this, keeping a table of previously calculated distances can help with performance.
EDIT: Such a loop might look like this:
Using python Syntax Highlighting
time_ = 0
y = 0
yv_prediction = yv
while y <= 0:
y += yv_prediction
yv_prediction += g
time_ += 1
I would use a kinematic equation to find the time needed. Specifically, probably this one:
[code]v[f] = v[i] + a * t[/code]
Solved for [i]t[/i], that gives us:
[code]t = (v[f] - v[i]) / a[/code]
So if the initial vertical velocity is called "yv" and the vertical downward acceleration is called "g", you might use this:
[code]time = 2 * yv / g[/code]
Then just multiply that by the horizontal velocity to get the distance. EDIT: Or rather, divide that from the distance to get the horizontal velocity. :)
But if your game's acceleration is nothing more than simplistic additions to velocity variables each frame (which is what Game Maker does if I'm not mistaken), that won't actually work. In that case, the only way I can think of other than hardcoding it is to use looping to simulate the trajectory. If you do have to do this, keeping a table of previously calculated distances can help with performance.
EDIT: Such a loop might look like this:
[syntax=python]
time_ = 0
y = 0
yv_prediction = yv
while y <= 0:
y += yv_prediction
yv_prediction += g
time_ += 1
[/syntax]