I have a 3d camera that is viewing a character that is moving. As the character is moving i want the camera to adjust itself so as to keep the character in the left third of the camera view.

I understand how to move the character in world space but how do i check in what part of the camera view it is in? And then know how to adjust the camera to compensate?

EDIT: I am looking for the maths behind this. I understand that if i have the character world space postiton, i can convert that to screen coordinates by applying the view and projection matrices. I then get the camera view in screen coordinates. I am able then to create some 2d bounding box that will move the camera if the character enters it.

enter image description here


2 Answers 2


Take a look at the lookAt matrix : https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function I can't explain to you myself as I use a matrix library for this, but there are tons of tutorials like this. This puts the point in world space you choose in the middle of the screen, and puts your camera where you want it be. You can then multiply that matrix by a yRotate matrix, or a rotate matrix with an axis of (0,1,0), with the angle that will place him at the wanted spot. I understand you wanted to understand the math, but matrices aren't complicated once you get how they work, and are just additions and multiplications packed to simplify everything for the gpu. I recommend this : https://webgl2fundamentals.org/webgl/lessons/webgl-2d-matrices.html This explains 2D matrix math, but in the 3D section he explains 3D math, and the lookAt matrix. Hope this helps.


Does it have to be fixed or smoothed? You need to figure out what position your center of the screen is at and how much distance it covers, the rest is just math. How you get that data however heavily depends upon the style of the game (3d or 2D)

  • \$\begingroup\$ I feel like the part you cover with "the rest is just math" is what OP is after. As such, this answer isn't very valuable. \$\endgroup\$
    – user35344
    Apr 26, 2018 at 12:53
  • \$\begingroup\$ As i said, it heavily depends on whether its 2D or 3D. Also since the question didn't specify what exactly the OP is after you can't be sure either. \$\endgroup\$
    Apr 26, 2018 at 18:23
  • \$\begingroup\$ @RIJIK added more info. its the maths parts i am looking for. \$\endgroup\$
    – SRG
    Apr 28, 2018 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .