0 votes

Hi,

SkeletonModificationsStacks (Bones LookAt and IK) are currently broken in Godot 4, and I'd like to have a simple bone lookAt Target function in GDScript

I've been trying quite a lot of things, and either the rotation end up wrong, or offseted by a 90deg on some axis for some reason

My best attempt:

var transform = skel.get_bone_global_pose(bone2_id)
var b = (skel.global_pose_z_forward_to_bone_forward(bone2_id, transform.basis.looking_at(b2_target, Vector3(0, 1, 0)) ) )
skel.set_bone_pose_rotation(bone2_id, b)

And for some reason, it needs an offset * Basis().rotated(Vector3(0, 0, 1), -PI/2) otherwise only the transform of the bone is aligned, but the bone is not aligned with it's transform -Z, But definitly not sure, also global_pose_z_forward_to_bone_forward is deprecated

I'm definitly missing something around the difference between local/global bone poses and maybe rest poses (also not sure about the Vector Up for the lookAt). But the documentation on Skeleton is quite limited.

Thanks for you help !

Godot version Godot 4.10
in Engine by (19 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.