# Calculate Initial Velocity to Reach Destination Based Off Time

Hello!

I’m trying to create a jump pad that can shoot an object/player to a specified location in 3D space. I know that the trajectory formulas require some initial velocity and angle but I would like to compute an initial velocity AND angle just based on how much time it should take the object to reach the destination.

Not sure if this is possible but thanks for looking!

• Caleb

Let me see if I understood your question right.

Given the position of the destination with respect to the position of the jump-pad, you want to figure out an angle of launch and an initial velocity that will get your player to the destination when he triggers the jump pad, correct?

This is more of a physics and math problem, but I’ll see if I can set you in the right direction at least.

First of all, in Unity, as much as possible, you want to think in terms of vectors. Solving for a vector will give you both angle and magnitudes, while thinking in terms of fewer variables. So here, you are trying to calculate the right initial velocity vector.

You sound like you are aware of the basics of trajectory formula. Just for the references, here. Don’t let the partial derivatives or the calculus scare you, it just means that your life is easier because you can treat each dimension independently. Points to note:

• There are infinite combinations of velocities and angles that can result in the trajectory you want, if you don’t worry about time
• The formula for the trajectory may not accurately represent what the Unity physics engine will execute with your computed parameters, since things like air resistance, gravity value, etc could be different.
• The math for trajectories in 3D space is just an extension of that in 2D space.

Are you assuming no deceleration of your player once launched? I will assume you are only expecting your target to be affected by gravity. This would make calculating some parts of the initial velocity (u) actually a little simpler. You have

``````p.x(t) = u.x*t
``````

p.x(t) is the x position of the player at time t w.r.t the jump-pad. Since you know t, and you know p.x(t) (the difference in x-position between the jump-pad and the destination), so u.x is easily calculated as p.x(t)/t. You can do the exact same thing for u.z to give you `p.z(t)/t`.
To obtain u.y, you use

``````p.y(t) = u.y*t - 0.5*g.y*t*t
``````

(g.x = g.z = 0, g.y = whatever your engine-set gravitational acceleration is)
Again, since you know p.y(t) and g.y as well as t, `u.y = p.y(t)/t + 0.5*g.y*t`

There you go! If you have other accelerating forces involved, just modify the equations appropriately, but basically, your initial velocity vector (angles included!) will be

``````[p.x/t, p.y/t + 0.5*g.y*t, p.z/t]
``````

Hope that helped, Caleb!