Skip to content

Instantly share code, notes, and snippets.

@Hangman
Last active November 17, 2023 05:57
Show Gist options
  • Save Hangman/43e6d02bf07f4ce0267b0282013f7c9a to your computer and use it in GitHub Desktop.
Save Hangman/43e6d02bf07f4ce0267b0282013f7c9a to your computer and use it in GitHub Desktop.
Godot look_at fix (avoid getting the aligned error)
# 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