Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having problem with locking one object on another. Lets image an turret which always targets flying plane. I come to this solution:

  1. Compute yaw = atan2(z2-z1, x2-x1)
  2. Compute pitch = atan2(y2-y1, z2-z1)
  3. Rotate

What do you think about such method? Is there any "faster" way without using atan2? Can I achieve same effect with just quaternions operations?

share|improve this question
Is this two questions? What are you asking? It looks to me like you asked a question about having a turret face an object, then gave us some unrelated code about orbital motion without even telling us what you want to know about it. – stephelton May 13 '12 at 21:07
like pictures show,I want my origin point to be in the center of orbiting objects not a part of the path just like it is now. – user1075940 May 14 '12 at 5:57
You're still asking two questions... – stephelton May 14 '12 at 15:10
up vote 1 down vote accepted

To get an object A to point towards a point B, then it's not difficult.

Vector current_heading = non_rotated_heading_of_object * object->rotation;
Vector target_heading = (target_position - object->position).normalize();
Vector axis = current_heading.cross(target_heading);
float angle = std::acos(;
Quaternion rotation = rotateAngleAxis(axis, angle);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.