I found one solution. First save the original rotation of the camera. Then set the camera to look at the target (character). Now calculate the offset value and apply it every time after using the look_at() function. Here's the code.
camera.look_at(character_pos, Vector3.UP)
camera.rotate_x(cam_rotation_offset.x)
if check_only_once:
check_only_once = false
cam_rotation_offset = camera_original_rotation-camera.rotation