Reputation: 471
I'm writing a program in Godot with GDscript that aims to change the position of multiple bones in an armature. The bone gets translated by a value calculated by the point I want the bone to move to minus the current position of the bone. translateValue = endPoint - currentPoint
However, all values must be in world coordinates or global position for the code to work. Godot has various methods to retrieve the bone Transform in order to access the position such as : skeleton.get_bone_pose() , skeleton.get_bone_global_pose , skeleton.get_bone_rest
. I tried using skeleton.get_bone_global_pose
but it didn't give the global position and seemed to still be relative to something. There's also the to_global()
method, but i'm not entirely sure what it does. Could someone explain the differences between these methods and how to get global position? Thanks!
Upvotes: 4
Views: 4263
Reputation: 40170
I'll start with these methods:
get_bone_rest
get_bone_custom_pose
get_bone_pose
First of all, get_bone_rest
gives you the default transform of the bone, relative to its parent bone. Then the other transform are stacked, in the above order.
Then we have:
get_bone_global_pose
This method gives you the final transform of the bone. And it is relative to the Skeleton
. That is, this transform already includes the previously mentioned transforms, combined from parent to child bone.
Thus, converting its result to world space is a matter of composing the transform of the Skeleton
:
$Skeleton.global_transform * $Skeleton.get_bone_global_pose(bone_index)
And we have:
get_bone_global_pose_no_override
As the name suggest get_bone_global_pose_no_override
ignores any global pose override. That's right, you you can override the global pose. To do that, use set_bone_global_pose_override
. See also clear_bones_global_pose_override
. These are all, of course, relative to the Skeleton
.
The method Spatial.to_global(vector3)
is unrelated to the Skeleton
. It transforms a vector from the local space of the node on which you call it, to world space. Which might also be useful:
$Skeleton.to_global($Skeleton.get_bone_global_pose(bone_index).origin)
Upvotes: 7