# Calculate jump velocity given horizontal distance and speed

I’m making a 3D platformer with a fairly consistently physics-based controller. Up until this point, my designer has been satisfied specifying jump height in meters. I can then calculate the vertical speed required to reach this height with the following method:

``````private float GetJumpSpeedGivenHeight(float height) => Mathf.Sqrt(-2f * Vector3.Dot(Physics.gravity, UpAxis) * height);
``````

However, we want to be able to describe a jump arc given a horizontal distance to travel, and a speed to travel that distance, without caring about the height. Basically a function which takes two floats and gives a Vector3. (We can assume the jump is axis-aligned for simplicity’s sake)

I understand that this would involve use of kinematic equations, but I’m at a loss as to how to continue. If someone could give me a nudge in the right direction that would be amazing.

Based on an old answer I gave here, there are multiple approaches you can take to this problem.

Since you’re describing “a speed to travel a certain distance without caring about height”, you can use a time-based approach (HitTargetAtTime() in my example), where the time is directly tied to horizontal distance traveled.

For example, by having a predetermined horizontal speed, the launch velocity would be calculated using something like:

``````public float horizontalSpeed = 50.0f; // Units per second, must be [> 0]
// ...
Vector3 flatFromTo = targetPosition - transform.position;
flatFromTo.y = 0f; // Simple example of eliminating height, assuming y-axis-only gravity
float flatMagnitude = flatFromTo.magnitude;

// timeToArrival = horizontalDistance / horizontalSpeed
Vector3 launch = HitTargetAtTime(transform.position, targetPosition, Physics.gravity, flatMagnitude / horizontalSpeed);
``````

In the end the answer was painfully simple. These give the upward speed required to make the jump.

``````public static float GetJumpSpeedGivenHeight(float height) => Mathf.Sqrt(-2f * Vector3.Dot(Physics.gravity, UpAxis) * height);
public static float GetJumpSpeedGivenTime(float time) => -Vector3.Dot(Physics.gravity, UpAxis) * 0.5f * time;
public static float GetJumpSpeedGivenSpeedAndDistance(float speed, float distance) => GetJumpSpeedGivenTime(distance / speed);
``````