Rotating an object to face another Object


Im trying to build an autopilot or AI into my ships. To do this I need the ships to be able to calculate where they need to turn to and then do it. Ie they have to steer themselves so they are facing another ship. Currently I caluclate how far off I am (in radians) on the xz plane and then rotate by that amount on the y axis. Then I caluclate how far off I am on the xy plane and rotate about the z axis. (as I use the x axis as the front of my ship). This seems to work most of the time although occaisionally it doesnt quite work. But if I execute it a couple times in a row it always works. Just wondering if there is a better way to do this.




  • Crazzy.
    You need to learn some vector maths. Its not as harsh as it sounds :) This may sound abit techy, but if you Create vector towards your target and normalise it. dot product your're facing vector ( normaly Z but i think you said that you use x ) with the target vctor and you will get a a result which is how close they are to faciong each other. You can use this to turn your object towards its target.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion