This could be my rotten coding, but I'm finding some odd behaviour in Unity with my animations.
PlayerBody has a SkeletonAnimation component, and a child object called PlayerHead, which also has a SkeletonAnimation. As a nice way of having the head animate separately to the body (for facial expressions/ talking etc) I'm setting its position and rotation every tick, to a Bone on the body animation:
public class LockToBone : MonoBehaviour {
public SkeletonAnimation ParentAnimation; // set in inspector
public string ParentBone; // set in inspector "HeadBone"
public string ourBone; // set in inspector "HeadBone"
private Skeleton parentSkeleton;
private Skeleton ourSkeleton;
private Bone parentBone;
private Bone tiedBone;
// Use this for initialization
void Start () {
parentSkeleton = ParentAnimation.skeleton;
parentBone = parentSkeleton.FindBone(ParentBone);
ourSkeleton = GetComponent<SkeletonAnimation>().skeleton;
tiedBone = ourSkeleton.FindBone(ourBone);
}
// Update is called once per frame
void Update () {
tiedBone.data.rotation = parentBone.worldRotation;
tiedBone.data.x = parentBone.worldX;
tiedBone.data.y = parentBone.worldY;
}
}
Works great. Unless I spawn TWO of the objects. In which case each Head skeleton is set to the position of the opposite Body's bone, not its own! So Head#1 moves in accordance with Body#2's position/rotation, and Head#2 moves in accordance with Body#1's position/ rotation.
Am I doing something mind-blowingly stupid here, or have I misunderstood how FindBone works?
Any help much appreciated!
d