Re: [Algorithms] Where is the enemy?
Brought to you by:
vexxed72
From: Ray <ra...@gu...> - 2000-07-25 01:39:17
|
"Aldo ." wrote: > > I'm building the AI module of my game, but I have a problem. > > Imagine you as a space ship pilot in the deep space. Your enemy apears on > the radar screen. You are at the "p1" position, "d" is your direction and > "u" is your up vector. Your enemy is at the position "p2". > How can I decide wich side must I turn? > ...clip... > > Any sugestions? > > Thanks in advance. > > Aldo Hi, Do you want your ship's up vector to match the enemy ship's up vector? in outerspace that's not really necessary since there is no true up. Ok, so what I would do is to use a quaternion to define a rotation from your orientation to the enemy's orientation. Get the direction of the enemy relative to you and your forward direction. Do a cross product and that's the axis around which you rotate. Do a dot product and that's the cosine of the angle which you rotate around that rotation axis. Then the rest is simple algebra to make a quaternion. Then you use that quaternion and turn it into a rotation matrix and appy it to your ship. Or if you have stored your current orientation as a quaternion, and with the new quaternion you can SLERP from one quaternion to the other over time. To do this though you must calc the new quaternion as an absolute quaternion as opposed to one that is applied to your current orientation. I hope this helps a little. - Ray |