Attempting to rotate arm bone towards a target (Node3D) using GDScript "correctly"

Godot Version

4.2

Question

Ok, so I have been able to modify the arm bone transforms using script before. Using the “global pose override” is simple enough. But the issue is getting the arm to aim in the proper direction.

Where I’m starting…
I have a simple blender animation of my character holding out it’s arm in a straight line.

What I want…
Point arm with gun at thing.

What have I been doing…
Get pose of upper arm bone.
Attempt to modify it’s transform to point towards target using a variety of methods. Looking_At(), Rotated_Local(), etc…
Apply with pose override.

And then sometimes it does nothing, other times it will attempt to do the thing, but the orientation is all whack.

I think I need to somehow get the upper arm bone’s global transform, disregarding it’s local space, and modify that, but I’m not sure how to do that…

Am I close, and if so how can I get to the right spot. If I’m doing this wrong please explain the proper methodology!

Solution Found!

I decided to just use SkeletonIK to rotate the arm, and it works fine. If anyone wants an explanation…

Add SkeletonIK node to Skeleton3D and link it to upper and lower arm (or shoulder / hand, whatever you need)

Make a Node3D and position at model shoulder (calling it Pivot for reference)

Make a child Node3D from shoulder Pivot and extend it out (calling it Mark for reference)

Set SkeletonIK Target to extended Mark

Rotate and adjust Mark to fix bendy arm if needed

Now, script Pivot Node3D to rotate towards target (look_at() works great for simplicity)

When ready, either click PlayIK at top of screen with SkeletonIK selected. Or call start() in script, referring to your SkeletonIK

If done right, rotating Pivot should reposition Mark, which the SkeletonIK tracks, meaning the arm extends to it. This should allow for effective target tracking. Use clamp() function to limit the Pivot’s rotation, and effectively the arm’s rotation.

Note I am working with a model with disconnected shoulders, so I don’t know if this will twist the heck out of your model, but hopefully the concept still works, and you can just adjust to fix deformation?

Hope this helps out in future!