The LookAt IK modifier can produce unintended results when used on objects that are not meant to rotate around the Y axis due to the modifier defaulting to using basis.Y when rotating the bone transform. I have attached an example from my project where I am using several LookAt IK modifiers to animate the secondary motion and aiming of my player character.
Unmodified Code:
# The bone_up_dir is defaulted to basis.Y Vector3 bone_up_dir = twisted_bone.get_reset_bone_global_pose().Basis.y.Normalized(); twisted_bone.LookAt(target_node.GlobalTransform.Origin, bone_up_dir);
This results in the weapons on the side of my player character flipping at extreme angles instead of pointing directly towards the IK targets as intended
Modified Code:
# Specifying the intended basis fixes the issue Vector3 bone_up_dir = twisted_bone.get_reset_bone_global_pose().Basis.X.Normalized(); twisted_bone.LookAt(target_node.GlobalTransform.Origin, bone_up_dir);
The issue is fixed by specifying which basis I want to be the bone_up_dir.
Proposed Fix/Change:
I don't use C# in Godot and don't really know how to do this, but I think adding an additional export variable that lets you specify the basis you want to rotate around would be a good fix for all cases here. Defaulting the Y basis would work for a majority of cases, but it doesn't work very well in some edge cases, like mine.