- Home /
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.
Answer by Eno-Khaon · Jan 28, 2021 at 03:39 AM
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);
Answer by EmmetOT · Jan 28, 2021 at 09:58 PM
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);
Your answer

Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
My character moves in seemingly random directions. 1 Answer
Velocity Movement & Physics Interactions by Rigidbody2D 0 Answers
Need help with the physics and angles of gerbils in a plastic ball.. 2 Answers
ForceMode.Acceleration estimated dst != covered dst with a single Addforce in effect 1 Answer