# How to calculate vector of projectile initial velocity

There are point A (origin) and point B (target). And also there is gravity vector G. I need compute initial velocity of projectile (throwing arc trajectory from point A to point B).

Also I need to control speed of projectile (Speed) and flexion of throwing arc.

How compute this?

• This is fairly complicated math, what should it be used for? Do you really have to know the initial force to hit the target exactly? If not then just cheat by trying out til you find homemade numbers that 'just works' – Valmond Dec 13 '16 at 9:16
• @Valmond I need to shoot from weapon (point A) with non-linear (arc) projectile directly to target (point B, considering the obstacles). Projectile spawned with specified initial velocity and gravity, but not moving to point B. I want correct trajectory by target. – Broly Dec 13 '16 at 9:21

Assume your variables are: initial velocity , initial position , and target position .

First, choose your initial y-velocity, and calculate the time it requires to reach its target on the y-axis using this equation:

If you want the projectile to reach its target while it's ascending, choose the plus sign, otherwise, choose the minus sign. (Note that gravity, g, should be < 0).

Now you can calculate the initial x-velocity by using this equation:

Likewise, for the initial z-velocity:

You can modify the curve of the arc by changing the initial y-velocity.

• +1 Good one! I think I misunderstood the question, if I compare our answers. – Artery Dec 13 '16 at 9:52
• media.giphy.com/media/l0MYuhmyKQYzYHY4g/source.gif But I got some calculation error between point B and actual point of arc collision. Whats wrong? – Broly Dec 13 '16 at 13:08
• Can you please tell me what values you chose? – WindyKeeper Dec 14 '16 at 8:54

Depending on how accurate you need to be and how much processing power you what to use for this, you could compute the position and speed of your projectile by using the semi-explicit euler:

Semi-explicit euler:

First calculate the new velocity:

• v(t + h, p(t)) = v(t, p(t)) - h*g

Than you calculate the new position:

• p(t + h) = p(t) + h*v(t + h, p(t))

Variables:

• v is velocity-vector
• t is your current time
• h is your timestep (e.g. 1 if you calculate every second)
• p(t) is the current position at time t
• In my context time is does not matter. I can't insert t to computations, I have only coords of start and end positions. – Broly Dec 13 '16 at 9:43