This is math for the stinger launcher. Not too tough. Basically its a missile that points to its target.

Need c's direction.

c is the difference, in 3 dimensions, between two origins a and b. a is the origin of the enemy, b is the origin of the tracker. We are going to use c again so remember it:

((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])

Now we need the distance between the origin of the two in one dimension:

distance = sqrt (((c)[0]*(c)[0]+(c)[1]*(c)[1]+(c)[2]*(c)[2]))

Now in order to change the direction of the tracker, we have to nudge it. I prefer to nudge it the closer it gets to the target, so that by 100 "units" the tracker is hooking absolutely to the target.

First we normalize the 3d distance (between 0 and 1) of the two points, c, in space. I'll use the variable "scale" here because i'll use it later.

length = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]

length = sqrt (length)

scale = 1/length

scale = scale * c[0]

scale = scale * c[1]

scale = scale * c[2]

Now we scale the vector by the length determined by distance / 100 (so that when the target is 100 units from the tracker, the tracker hooks absolutely)

(c)[0]=(c)[0]*(scale)*(1/distance)

(c)[1]=(c)[1]*(scale)*(1/distance)

(c)[2]=(c)[2]*(scale)*(1/distance)

Then add the new scale to the vectors the target is currently moving (b is an array of direction[] and angles[] of the tracker)

(c)[0]=(c)[0]+(b)[0]

(c)[1]=(c)[1]+(b)[1]

(c)[2]=(c)[2]+(b)[2]

Normalize Again:

length = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]

length = sqrt (length)

scale = 1/length

scale = scale * c[0]

scale = scale * c[1]

scale = scale * c[2]

Now copy the normalization to the direction of movement, b, so the tracker moves towards the target:

(b)[0]=scale

(b)[1]=scale

(b)[2]=scale

Note that movement is normalized. Physics of movement are beyond the scope of this, and I have no patience.

Finally point the tracker (roll, pitch, and yaw) to the enemy, can't have a tracker that just floats around like a ghost. We need to find the inverse tangent between two vectors, then convert the radians to degrees to "point" the tracker.

yaw = (- i log(c[1] + i c[0] / sqrt ((c[1] + [c]0)^{2}) * ( ^{180}/_{p)
}pitch =(-i log(c[2] + (sqrt (c[0]*c[0] + c[1]*c[1])) ) / sqrt ((c[2] +(sqrt (c[0]*c[0] + c[1]*c[1])^{2}) * ( ^{180}/_{p)
}Roll = We don't care about roll, but if you want you can always spin it some for effect, or always keep it at bottom facing ground level (0)

How does this look in ansi c? With macros and pointers for just about everything its simple.

VectorSubtract (blip->s.origin, ent->s.origin, blipdir);

dist = VectorLength(blipdir);

VectorNormalize(targetdir);

VectorScale(targetdir, (100/dist), targetdir);

VectorAdd(targetdir, ent->movedir, targetdir);

VectorNormalize(targetdir);

VectorCopy(targetdir, ent->movedir);

VecToAngles(targetdir, ent->s.angles);