# Camera follow 3D Object OpenGL

I'm trying to make my camera follow a 3D object, the X and Y values from the camera position are the same as the 3D object, but the Z axis is not the same, it has an offset of 13.0f so the camera looks to the object from a distance. The problem is that, the more I go up with the object, more the object disappears on the screen, its like the camera is following it slowly, or like, since the camera is far away then the object goes up faster than the camera, so how do I center the object in the middle of the camera?

[my current code for the view matrix of the camera]

view = glm::lookAt(position, position + forward, up);

• Could you provides us with a bit of code? In order to help you we need to have as much information about your problem – user100681 Nov 12 '17 at 9:06

Hard to tell how you are using it but if you set it up like this,

glm::lookAt(cameraPosition, targetPosition, up);

then it should work.

• yes but in this case, what the "cameraPosition" would be ? if the second argument is the targetPosition, what is the cameraPosition? I thought the first argument is supposed to be the targetPosition and the second a forward vector, because you know, I want the camera X and Y values to be the same as the object X and Y values – khofez Nov 12 '17 at 10:57
• Yes, the camera position is the camera X, Y, Z components. The lookAt function will make a rotation matrix from there, "looking at" the target. Maybe you don't need this function right now because your camera is always looking down, is that correct? You could set the orientation of the camera just once then. – Jay Nov 12 '17 at 11:04