How to apply a pose to a bone after an animation in godot 4?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dmonet

I’m working through rotating a playermodels spine bone up/down based on mouse input. I originally used set_bone_custom_pose as it allowed posing after an animation played from an AnimationPlayer, but it’s no longer supported in godot 4.

I’ve tried a couple solutions online (seen below), but the axis_local is misaligned when rotating and can’t seem to get it quite right.

var spine = skeleton.find_bone("spine_02")
var bone_pose = skeleton.get_bone_global_pose(spine)
var bone_to_global = skeleton.global_transform * skeleton.get_bone_global_pose(spine);
var axis_global = Vector3.UP
var axis_local = bone_to_global.basis.transposed() * axis_global

bone_pose = bone_pose.rotated(axis_local.normalized(), rot)

skeleton.set_bone_global_pose_override(spine, bone_pose, 1, true)

Is there equivalent functionality in godot 4 for set_bone_custom_pose?

Misaligned Axis

:bust_in_silhouette: Reply From: dmonet

For anyone searching this question, I solved it by using rotated_local instead of rotated:

var spine = skeleton.find_bone("spine_02")
var pose = skeleton.get_bone_global_pose_no_override(spine)

pose = pose.rotated_local(Vector3.FORWARD, rot)

skeleton.set_bone_global_pose_override(spine, pose, 1.0, true)