0 votes

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.

https://imgur.com/a/sXsIAXN

asked Jun 21 in Engine by ville (47 points)
edited Jun 21 by ville

1 Answer

0 votes
Best answer

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
answered Jun 21 by ville (47 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.