First I'll explain which objects I have.
There is a camera with position x, y, z, pitch and yaw variables.
There is a player with x, y, z and rotationY variables.
There is also a terrain, the camera the camera cannot get below a certain point (10f above the terrain), it keeps 'floating'.
I can change the pitch manually in-game with this code:
float pitchChange = Mouse.getDY() * 0.2f;
pitch -= pitchChange;
In the image below. The arrow represents the camera pointing direction and the color matches the player. The red one is how it is suppose to be on a flat terrain. As you can see, when I move downwards on the terrain, the camera keeps pointing forward instead of pointing to a certain point on my player, until I come back up to the same height or adjust the pitch manually. How can this be fixed by pitching the camera? (See second image).
How it is right now:
How I want it: