Sign in to follow this  

How to get a camera to follow?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this