Godot Version
v4.3.stable.official
Question
I’m trying to get a character’s head to follow a camera as they speak into it by setting an animation key frame value using the camera for Transform3D.looking_at and adding that to animations already playing in the animation tree.
at 0,0,0, looking straight ahead, the head points the right way, but as soon as the camera moves, or the character moves, the head points anyway but where I want it to. There’s gotta be something I’m egregiously misunderstanding here. Any help would be appreciated!
extends Skeleton3D
var head_bone_index = find_bone('neck_M_03_jnt')
@export var head_target: Node3D
@export var head_up_vector: Node3D
@onready var animation_tree = %AnimationTree
@export var aim_animation: Animation
func _process(_delta: float) -> void:
# Head Aim Constraint
var head_position = get_bone_global_pose(head_bone_index)
var global_head_pos = head_position * transform
var head_target_position = head_target.global_position
var head_lookat_transform = global_head_pos.looking_at(head_target_position, Vector3.UP, true)
var lookat_rotation = Quaternion(head_lookat_transform.basis)
aim_animation.track_set_key_value(0,0,lookat_rotation)