Jump to content
  • Advertisement
Sign in to follow this  
gundark

How to get a camera to follow?

This topic is 4753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I am attempting to get a camera to follow an object (in this case a spaceship) so that is at facing the same direction as it (in 3d) but about 10 units back. So I thought, as the object had a velocity vector anyway, that I could just reverse it and then scale it to the right amount to find the correct position for the camera. The only problem with this is that when the object isn't moving the velocity is 0 and therefore has no direction. I decided to keep track of the angles (all 3 of them) that the object was rotated, and then create a direction vector from them. The only problem... I've completely forgotten how to do that. Too much calc, not enough trig I guess. Anyway, if anybody could help me out with any idea what formulas I am supposed to be using for any part of this I would be very grateful. In the meantime I will be desperately searching my house for my old math book. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If the object has an orientation/position matrix (or you can make one), simply transform the camera's position relative to the ship by that matrix.

For example, if the ship faces in the direction of the local Z axis, then the relative location of the camera is [0, 0, -10]. Transform that vector by the ship's orientation/position matrix to get the camera's location in world space.

Furthermore, to get the camera's orientation/position matrix (assuming it points in the same direction as the ship), simply multiply this matrix by the ship's orientation/position matrix (assuming D3D):
    1   0   0   0
0 1 0 0
0 0 1 0
0 0 -10 1
This matrix means that the camera is pointing in the same direction as the ship and is 10 units behind it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!