• Unity
  • How can I get position of Bone

Related Discussions
...

The Spine Runtimes Guide is what you want:
Spine Runtimes Guide
You can get the bone with Skeleton findBone then Bone worldX and Bone worldY are the bone's world origin (what you called the bone's "root"). The tip of the bone is x,0 in the bone's local coordinates, where x is the Bone length. You can use Bone localToWorld, in spine-csharp that is something like:

float tipWorldX, tipWorldY;
bone.LocalToWorld(bone.Length, 0, out tipWorldX, out tipWorldY);

Dear Nate, Many thanks for your answer!
That's what I know!

You can also use a BoneFollower component, which can be attached to a separate GameObject. It will have it's transform values set to follow the bone every frame (with additional configurable settings).

8 months later

Hi Nate,

I'm just trying to draw all my bones, for that I'm trying to get bone's points, as you've suggested:

var bones = skeleton.Bones;
foreach (var bone in bones)
{
    float rootX = bone.WorldX;
    float rootY = bone.WorldY;

float tipX, tipY;
bone.LocalToWorld(bone.X, 0, out tipX, out tipY);
...
}

But I'm missing something, because my Spineboy looks terribly wrong.
I know, not all "bones" are "bones", but if I exclude those, the boy has still problems.
I'm not applying any animations/transformations for the skeleton, only setting the Scale for SkeletonBinary while reading skeleton data.

When I'm rendering the slots with images and applying animations, everything is right, it's just this "bones view" makes me troubles.

Best,
Anton

Hmm. You are using bone.X instead of bone.Length, maybe that is it?

Hi Nate,

yes, you are right, thanks! That's it.
I was looking for the Length in the Bone, but it's part of the BoneData.
So, the solution is:

bone.LocalToWorld (bone.Data.Length, 0, out tipX, out tipY);

Best,
Anton