Getting a look at point above moving character in 3D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ville

I want to get a look at point above my character while using look_at(Vector3 target, Vector3 up). The idea is that I want to set the camera position and rotation in editor. Then I want the camera to keep looking at that same direction while following the charter movement with look_at function. Using the character’s location vector changes the camera’s original looking direction which is exactly what I want to avoid. I hope next image clears things a little bit.

:bust_in_silhouette: Reply From: ville

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