Last active
November 17, 2023 05:57
-
-
Save Hangman/43e6d02bf07f4ce0267b0282013f7c9a to your computer and use it in GitHub Desktop.
Godot look_at fix (avoid getting the aligned error)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written for Godot 4.2.x | |
class_name LookAt | |
static func safe_look_at(node: Node3D, target: Vector3) -> void: | |
var direction: Vector3 = (target - node.global_transform.origin).normalized() | |
for up in [Vector3.UP, Vector3.RIGHT, Vector3.BACK]: | |
if abs(up.dot(direction)) != 1: | |
node.look_at(target, up) | |
break | |
# How to use: | |
# LookAt.safe_look_at(your_node, your_look_at_target_position) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment