Anyway to get the position of a bone if it was following the playing animation

Godot Version

4.5 stable


So I’m currently working on a little system in my project, the goal is that the head of the character should look in the general direction that the camera is pointing.

Now for some context the “head” I refer to is actually just a BoneAttachment3D that contains the heads mesh and what not.


Any who the main issue is that cause I have the Override Pose property enabled, the head as you can probably guess, wont move with the animations, allowing me to rotate it to face the direction I desire. The issue arises when I introduced a crouching animation, which lowers the position the head should be at, causing the head to look like its floating.

Now on the one hand I can just brute force it and try to figure out the position I need to put the head manually, but then it wouldn’t be smooth when you transition from crouching to idle or vice versa.

So I was curious if there’s a way to get the position the head would be at if the position wasn’t being overridden, and was instead following the animation. And maybe also the rotation.

I have searched the documentation along with just searching online and I haven’t been able to find anything that solves the issue yet. Which might be a cause of me being dumb, as I’ve never used bones or skeletons much before this :sob:

Code

# Skeleton refers to well, the Skeleton3D that contains the bones
# HeadJoint is the name of the BoneAttachment3D that connects the torso and the head.
# Camera.CameraNode refers to the Camera3D that the user is viewing from.

var AnimationPo = Skeleton.get_bone_global_pose(HeadJoint.bone_idx)
HeadJoint.look_at(AnimationPo.origin + (-Camera.CameraNode.global_basis.z * 45));
HeadJoint.rotation_degrees.x = clamp(HeadJoint.rotation_degrees.x, -40, 35);
HeadJoint.rotation_degrees.y = clamp(HeadJoint.rotation_degrees.y, -70, 70);
HeadJoint.rotation_degrees.z = 0;

Also if it helps this is being run in the _physics_process function.

If I need to add any more details or you have any questions feel free to ask!
Thanks in advanced!

1 Like
  1. Create an animation of the head rotating.
  2. Blend the head animation in using an AnimationTree with a BlendSpace and only have it affect the head bone.
  3. Use your code to call the BlendSpaceAnimation each frame with a value containing the direction you want the animation to go and how much to move that frame.

There is a Skeleton3D.get_bone_global_pose_no_override() which may work but you should probably use a LookAtModifier3D node to do that as those functions are being deprecated in favor of the SkeletonModifier3D nodes. You can read more about why here:

2 Likes

Hello again!

So what you mentioned did work for the scenario I provided, but now I need some way to add onto the position the bone would be at if it was following the animation, allowing me to offset the bone from its original position.

I checked the list of SkeletonModifier3Ds and couldnt find anything that suited what I needed, nor could I find a function that does what I need, so here I am again!

Thanks in advanced, and thanks for all your previous help!