# How to get a camera to follow?

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

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

1. 1
2. 2
3. 3
4. 4
Rutin
19
5. 5

• 14
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632926
• Total Posts
3009252
• ### Who's Online (See full list)

There are no registered users currently online

×