## 3D Homing Missile

Disparity
Unregistered

Post: #1
How can I make a homing missile? I've tried working with quaternions a bit, but without success.

Currently, my missile has a vector for its current location, a float for speed, and a quaternion for orientation. How can I gradually rotate the quaternion to lock onto a specific target, given the aforementioned variables?

Also, how would I apply the quaternion to openGL?
Member
Posts: 28
Joined: 2003.10
Post: #2

You'll need to convert the Quaternion of the missile's orientation to an OpenGL 4x4 rotation matrix that you can use when drawing the missile.

To turn the missile towards its target, ou'll either need to calculate the minimum arc Quaternion that represents the angle between the direction vector of the missile's flight and the vector from the missile's location to its target location, and apply a fraction of it to the missile's orientation each frame to turn the missile towards the target.

Or calculate the axis the missile has to turn about in order to face the target (the cross product of the missile's direction vector and the vector from the missile to the target), and turn the missile a fraction of an arc about that axis each frame.

Code to calculate the Quaternions to perform each of these steps can be easily found. There's some in my craptacular source to Oolite (vector.c), but I use a different algorithm for my homing missiles (it's more hokey - I wouldn't recommend it).

-- Giles Williams
Oolite - retro space-sim agogo
Oldtimer
Posts: 832
Joined: 2002.09
Post: #3
One thing to remember - you only need to rotate on two axes, you can disregard the "spinning" axis. That should simplify the maths a bit.
Disparity
Unregistered

Post: #4
Does that eliminate gimble lock?
Oldtimer
Posts: 832
Joined: 2002.09
Post: #5
Actually, I think it does. I'm not very sure about it, though.
However, I stumbled upon another interesting way to go about it in the GameDev.net forums:
Take the missile's current heading vector, and the vector from the missile's position to the target's position. These two form a plane that intersects both ships. Take the cross product between the vectors. You now have the normal of that plane. If you rotate around that normal, you are rotating on a plane that contains the missile and target. That is, the problem of steering towards the target is reduced to one variable - the missiles angle on that plane! I haven't tried it, but it seems really really cool and definitely worth investigating.
Disparity
Unregistered

Post: #6
Yah, your other way worked just fine and I think it did take out gimble lock.