I'm no expert on cameras, but let me get you started.
Think logically what you want to do. If you look at the player directly, it will do exactly that, which isn't what you want. Instead, you want to look at something else, which can vary. So, create another object(or you can just store it in variables). This object could be either where the player is pointing, it could hang out to the right ear of the player avatar, or different things. Then, make your camera look at that instead. This concept is great as well for example if you want to change things, like near/far, or maybe have the view either get ahead of where the player is moving, or lag behind, you can adjust only the separate object and keep the camera looking at the same thing.
The trick to this is not so much the separate object, but the position of the camera. You would likely want to have some method of detecting what direction the player is looking, and modify that vector to give a sort of angle and position where you think the camera should be. Draw it out, write some simple vectors, see how they are related and then convert them to get what you want in code.
The last thing I should mention is that you should almost always lerp/tween your camera, both the position and the lookAt spot, in order to keep things smooth. The main exception to this is if you want an instant "look" at something somewhere else, and even then sometimes game designers want to make it smooth instead of instant.
↧