Time to improve (and rewrite) the autopilot.. now i can select an object using the mouse, the next step is to move my ship to the selected destination.
The autopilot is a state-machine that has a lot of step, but you can summarize it into two big "macros":
- align the ship to a selected direction
- move the ship (or stop it).
I need a function that give me the thrust power of the engine from the angle between direction and final orientation: the more distant i am, more power the engine should provide. Otherwise, when the angle is small, the engine should provide less energy.
A good solution is to use the dot product between destination vector and right/up vector. The dot product between u and v is defined like |u||v|cos(angle) where angle is angle between u and v. If u and v are unitary, the cross product give me the angle.
For yaw, the cross product between destination and right is a function that is = 0 when right is normal to direction (and it's true when direction is equal to destination..), is > 0 when direction lies left to the destination, <0 when direction lies right. Perfect for my needs!
Finally, i've to normalize for angles > 90 degrees:
if (angle > 90) { if (dotproduct > 0) dotproduct=1; else dotproduct=-1; }
For pitch is the same, but i use the up vector instead right.
The result is shown in the video.
There's some "freeze": is an issue of my laptop (i've some problem with vista and the hard disk drivers..), not of the game :)
No comments:
Post a Comment