# Projectile Aim Prediction with Target Acceleration and Bullet Deceleration Varying with Angle

I previously asked a question about this topic here, and now I'd want to review if the offered solutions worked, and then frame a new inquiry based on the difficulties and issues that resulted.

So my previous post briefly summarized, what I'm attempting to do is calculate the Impact point of a Bullet and a moving Target in 3D Space based on the Bullet's Position, Target Position, Bulletspeed, Target Velocity and Target Acceleration.

The only variable I was lacking to estimate the impact point was the time it would take the bullet to reach the target, which I could solve using the formula below thanks to this post:

\begin{align} 0 &= t^4 \left(\frac 1 4 \vec a \cdot \vec a \right)\\ &+ t^3 \left(\vec a \cdot \vec v \right)\\ &+ t^2 \left(\vec a \cdot \vec p + \vec v \cdot \vec v - s^2 \right)\\ &+ t^1 \left(2\vec p \cdot \vec v \right)\\ &+ 1 \left( \vec p \cdot \vec p\right)\\ \end{align}

Right now I'm using this C++ quartic solver which gives me the time from the formula above which looks like this:

    double t4calc = (TargetAcceleration.Dot(TargetAcceleration)) / 4;
double t3calc = (TargetAceleration.Dot(TargetVelocity));
double t2calc = TargetAcceleration.Dot(relativepos) + velocity.Dot(TargetVelocity) - bulletspeed * bulletspeed;
double t1calc = 2.0 * destination.Dot(TargetVelocity);
double tcalc = (relativepos.Dot(relativepos));

std::complex<double>* solutions = solve_quartic(t3calc / t4calc, t2calc / t4calc, t1calc / t4calc, tcalc / t4calc);


using solutions->real() it returns the time it takes to hit the target in seconds.

The Problem:

Since I assumed that the Bullet's velocity is constant and hence does not contain acceleration, the function above only include the target's acceleration but disregard the bullet's acceleration.

Now I discovered that the Bullet has also an acceleration and that it slows down over time.

Unfortunately, I can't just use a constant acceleration like -10M/s since the bullet's speed and acceleration also fluctuates based on the pitch view angle of the player.

Because using the pitch view angle for a f(x,y) calculation would be tedious, I decided to switch from viewangle to relative height and distance of the target, as my pitch view angle varies depending on how high and far the target is from me.

So, collecting some data and testing around, as well as using curve fitting, I was able to obtain the following function, which gives me the Time the Bullet need to Reach the Target in Seconds, based on the relative height and distance of the Target:

double a0 = 0.28891;
double a1 = 0.00147988;
double a2 = 0.0000116694;

double x1 = DistanceToTarget;
double x2 = Targetheight - Playerheight; //relative height of Target

double TimeToTarget = a0 + (a1 * (x1^1.2)) + (a2 * (x2^1.75)) //Returns Time in seconds it needs to reach the Target (If Target is stationary)


Okay so using the function above I could get the time which the Bullet needs to hit the Target (if the Target is not moving and standing at one point).

But of course I want the Time it needs to hit the Target if the Target is moving and accelerating..

So now I could calculate the bulletspeed in M/s by dividing the current distance to the target by the time obtained from the function above and insert it into the quartic solver function to get the time which the bullet needs to hit the moving and accelerating target based on the predicted position right...

Wrong.. this won't be accurate for the quartic solver function above, since it would use the bulletspeed computed for the target's current distance, while it should be using the bulletspeed calculated for the target's distance at impact. I hope you can follow me here.. if not feel free to ask about it.

Final Question:

So to solve this problem I'm wondering whether I can somehow include this TimeToTarget function into the previous quartic function. Otherwise the speed will be calculated incorrectly and the result will be wrong.