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

in Engine by (50 points)
edited by

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
by (50 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.