I haven't figured out how to insert this into the code myself, so I'm posting it here.
This is in 2D, but adding a third dimension should be a piece of cake.
Ah screw it, I'll do it in 3D:
void Missile::steer(float timestep, Position3D *target)
{
float dx = target->x - x, dy = target->y - y, dz = target->z - z; //Calculate vector from missile's position to target
float distanceToTarget = sqrtf(dx * dx + dy * dy + dz * dz); //Calculate magnitude of that vector
//Find the direction to accelerate in, in the moving reference frame of the target
float dvx = dx * preferredSpeed / distanceToTarget - (vx - target->vx);
float dvy = dy * preferredSpeed / distanceToTarget - (vy - target->vy);
float dvz = dz * preferredSpeed / distanceToTarget - (vz - target->vz);
float inv = timestep * acceleration / sqrtf(dvx * dvx + dvy * dvy + dvz * dvz); //Used to normalize the acceleration vector
//Normalize it
vx += inv * dvx;
vy += inv * dvy;
vz += inv * dvz;
}
The missile attempts to maintain constant speed (and possibly velocity) relative to the target's motion. So it will lead automatically, making it very hard to avoid. I would recommend using a weapons.tbl flag, such as "Newtonian Missile".
What this doesn't do is take into account the heading of the missile. Realistically, the missile would either have to be changing heading rapidly or have a bunch of small steering thrusters. However, since it's FreeSpace, I think we can get by with letting modders put fake steering thrusters on their missiles.
Also, this would go well with an $Accel entry for secondaries, to control acceleration used in the formula.