Rotating an object to face another Object - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Rotating an object to face another Object

CrazzyBCrazzyB Posts: 3Member
Hello,

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.

Thanks

CB

Comments

  • WudanWudan Posts: 66Member
    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.