Ok as I understand it this should be simple but I am obviously missing something…
I am useless with math. wiki article
This function is part of an AI Steer Library and should be guiding things… missiles etc into other objects. I thought I should just be able to compare the change between the Line of sight vectors and use the delta to adjust the new heading? this kinda works but causes a “near miss” 9 times out of 10… So what have I missed somethings wrong with my understanding of the problem but I can’t workout what!?
The last thing it does is to add the difference between the last LOS and the current LOS to the current one in order to steer into it and create a new heading for the next tick
Goto http://www.asteroidwars.com/player.html to see the current results… the guidance is on the missiles only.
protected void SteerToIntercept(float weight, SolarObject target, float speed, KinematicState thisAutomatonsPrevious, KinematicState targetsPrevious)
{
DesiredVelocity desired = new DesiredVelocity();
Vector3 tpos1, tpos2, los1, los2, pos1, pos2, dir, losChange;
pos1 = thisAutomatonsPrevious.Position;
pos2 = thisAutomaton.Current.Position;
tpos1 = targetsPrevious.Position;
tpos2 = target.Current.Position;
los1 = (tpos1 - pos1).Normalized;
los2 = (tpos2 - pos2).Normalized;
if (los1 == Vector3.Zero) losChange = Vector3.Zero;
else losChange = los2 - los1;
dir = los2 + losChange;
desired.Speed = speed;
desired.Direction = dir;
desired.Acceleration = 1f;
desired.Torque = 1f;
desired.SteerWeight = weight;
desiredVelocities.Add(desired);
}