The problem, in a nutshell, is that I cannot figure out how to attach a "follow" 3rd person camera to my model in 3D space.

I've done quite a few cameras over the past year. But pretty much all of them have been following a 2D plane of some sort. Whether we're talking 1st person or some sort of follow camera, the cameras that I've done have followed objects moving across a relatively flat plane, such as a terrain or an actual plane.

My current project is litterally in 3D space. It's basically a space ship simulator. But I'm finding that I cannot implement the camera that I had intended to implement.

Here's what I

**want**to happen: I imagine a vector/arrow sticking up out of the top of my ship model that the camera should look at the tip of the vector. The camera should orbit around this point and (the hard part) should remain attached to this point. So, as the ship yaws, pitches, and rolls, the camera should follow it through every move and remain at the exact same spot relative to the ship.

Originally, I thought I could do this with two vectors and quickly discovered that that totally doesn't work in full 3D space. It works great when following something moving across a plane, but as soon as you go into wild maneuvers you discover that the vectors remain basically parallel to the plane they started on. It just doesn't work at all.

So, I've been working on animating a lot here lately, and I've been working with transformation matrices. This seemed like a perfect place to apply them and I've got it

*almost*working.

The theory was to move the model with its world matrix. Then a camera look at point would be defined through a transformation matrix that would be relative to the model's world matrix. (WorldMatrix * CameraLookAt = where the lookat point is). Then a second transformation matrix would define the camera "eye" point. (WorldMatrix * CameraLookAt * EyePoint = Where the camera's eye point is at). Everything is defined relative to one another at that point. So the camera is firmly attached to the model and follows it through rolls and such.

I suspect the problem may be due to the fact that I'm using these 3 matrices to then help me define a view matrix for the camera. And as you know, the view matrix is inversed compared to other matrices. I don't know if that's part of the issue or not.

Anyway, here's the current behavior that's wrong: The camera perfectly follows the ship through rolls and yaws regardless of whether it's clockwise or counter clockwise. The problem comes when the ship pitches. When it pitches the camera does not move correctly. It looks like the ship pitches and the camera remains in its original position without following the ship. However, what "could" be happening is that the ship and the camera are rotating through opposite rotations (one rotating clockwise and the other counterclockwise for example). I'm not sure of any way to tell which is happening. Hmm, maybe I could answer that if I pay more attention to the skybox in the background; it shouldn't move if the camera is actually stationary.

Anyone have any ideas on what my problem might be? Any ideas on why it Yaws and Rolls perfectly but goes crazy for Pitch?

Anyone have totally different ideas on how to attach a camera to a space ship model?

This post has been edited by **BBeck**: 23 July 2013 - 01:04 PM