# Moving vector shooting at other moving vector

The following code creates an accurate shot to be made at a moving target from a stationary position. (ie a tower or non-moving vector). It works GREAT, but I need it to consider the movement of the shooter. I believe I subtract the shooter's movement from the target's movement, but I don't know what part of the code this would apply to. Please help. I have an assignment due tomorrow and this is working perfectly except for calculating the shooters movement.

    Vector totarget =  target.position - tower.position;

float a = Vector.Dot(target.velocity, target.velocity) - (bullet.velocity * bullet.velocity);
float b = 2 * Vector.Dot(target.velocity, totarget);
float c = Vector.Dot(totarget, totarget);

float p = -b / (2 * a);
float q = (float)Math.Sqrt((b * b) - 4 * a * c) / (2 * a);

float t1 = p - q;
float t2 = p + q;
float t;

if (t1 > t2 && t2 > 0)
{
t = t2;
}
else
{
t = t1;
}

Vector aimSpot = target.position + target.velocity * t;
Vector bulletPath = aimSpot - tower.position;
float timeToImpact = bulletPath.Length() / bullet.speed;//speed must be in units per second

• a, b, c, p, q, t... that's good, you still have 20 variables that you can name. Seriously, though: you want other to help you? Name your variables meaningfully so we don't have to reverse engineer what you're trying to achieve. – Vaillancourt Oct 29 '15 at 15:51

var velocityDiff = target.velocity - tower.velocity;