## Missile targeting

Thanks,

Iceman

Basically I get the horizontal and vertical angles to the target and from that I calculate yaw and pitch inputs that I feed to the physics engine. It's a bit complicated but I get the vector to the target and my heading vector, construct a couple of shortest arc quaternions and get the angles from them.

KenD

Thanks,

Iceman

The problem with a missile is how to make it steer towards the target in a 3D environment and I solved it as I described above. I find out how much off course I am (the angles) and then try to minimize those angles.

I haven't found a ready made solution to the problem so I had to combine several things like getting the direction to the target, my direction, getting the angles for how much I'm off and then steer in the opposite direction to minimize the difference.

KenD

Quote:Originally posted by KenD

The problem with a missile is how to make it steer towards the target in a 3D environment and I solved it as I described above. I find out how much off course I am (the angles) and then try to minimize those angles.

KenD

Ok I know how to make the vectors work with an angle, but what is the formula to find the minimum angle?

Thanks,

Iceman

if you have two normalised vectors: the first pointing in the direction of the target and the second pointing in the direction of the missileÖ

Öthen their vector cross product is an axis vector for the rotation that will take one onto the other, and their vector dot product is the cosine of the angle between them.

If they aren't normalised you'll get a non-unit axis vector and plain wrong inverse cosines, so normalise them.

You should be able to optimise slightly by only bothering to steer if the dot product is > 0.95 or so - this should save needless course-correction calculations when the missile is on target.

edit - gibberish

Thanks,

Iceman

Thanks,

Iceman

A simpler, probably faster (yet less precise) way to do this is to create a vector which represents the velocity of the missile. Then get the distance (use the fast formula by not calling sqrt, the squared distance is fine for comparison) for the missile to the target if the missile continues on the same path. Next, get the distance from the target if the missile turns to clockwise this turn, and also if the missile turns counter-clockwise this turn. The distance which is the shortest is the one which the missile should do (ie if turning left shortens the distance to the target, then do that). One side effect of this is that if the turn value is too large, the missile may orbit around the target. :-)

Another method which is better than the one proposed, yet more complicated, is to use quaternions and do linear interpolation between them. This, I believe, produces the best results.

In either case, if your game calls for having lots of missiles, you'll not be very optimized if you call any of the trig math functions (like atan). However, if you only have a couple it probably won't matter.

Cheers

Another method which is better than the one proposed, yet more complicated, is to use quaternions and do linear interpolation between them. This, I believe, produces the best results.

In either case, if your game calls for having lots of missiles, you'll not be very optimized if you call any of the trig math functions (like atan). However, if you only have a couple it probably won't matter.

Cheers

Virus Out

Big Bang Board Games

Adventures on Pirate Isle

Solace - Strategy, War, and Glory!

The Belt

Thanks,

Iceman

quaternions = yuck :eek: