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;
The Earth always accelerates directly towards the Sun, and yet it’s been missing for billions of years…
You will need more sophisticated maths than I know to target perfectly … after all it is Rocket Science.
But maybe you can settle for a heuristic? Its hard to see how the snippet of code would fit into the bigger picture, but if you target the position half way between current and target, rather than the target itself, that should give your algorithm time to stabilise (if it is sufficiently damped).
Yeah that was it, thanks… It needed more dampening… Since I was using a set amount of overseer (1x the slope delta) (I think sidewinders do this) so It would ‘wobble’ ever so slightly but it suddenly got much worse just before it hit the target, causing it to over compensate and miss (only just mind)… But I noticed the effect got worse the more torque I gave it… So I dampened down the torque and rate of turn and it hits every time now yay
I guess I am missing the proportional bit out of the equation, somewhere there must be a scalar that needs to be based on the rate of closure to get it exact irrespective of turn rate but its good enough for now… at least I know it basically works and just needs tweaking and its not totally wrong.
That code comes up with a single weighted vector request (for in this case intercepting a target) that goes into a pot of requests for the controlling AI instance and a weighted average is then calculated and send to the physics engine to process.
But for missile guidance (a cut down part of the AI library) it’s the only request in there so there is nothing to average out it will just take the results this method gives.