- Modifié
Hi,
I'm a new user to Spine and I'm trying to use it to "track" a bone so that I can attach a particle system to it.
With my script I'm getting some weird behaviour - mainly the position of the bone does not seem to be correct.
using UnityEngine;
using System.Collections;
using Spine;
using System.Collections.Generic;
public class BoneLocator : MonoBehaviour {
[SerializeField]public tk2dSpineSkeleton playerSkeleton;
Bone bone;
[SerializeField]private List<Bone> someList = new List<Bone>();
// Use this for initialization
void Start () {
// //Had to be removed as it seems the list of bones is not ready at this point.
// someList = playerSkeleton.skeleton.Bones;
// bone = playerSkeleton.skeleton.FindBone("Head");
// someList = playerSkeleton.skeleton.Bones;
// Debug.Log("HERE I AM, I have a list of bones with length: " + someList.Count);
//
// for(int i = 0; i < someList.Count;i++){
// Debug.Log("Bone Name: " + someList[i].Data);
// }
}
// Update is called once per frame
void Update () {
someList = playerSkeleton.skeleton.Bones;
// Bone bone = skeletonComponent.skeleton.FindBone("boneName");
// transform.position = new Vector3(bone.WorldX,bone.WorldY,transform.position.z);
// Debug.Log("HERE I AM, I have a list of bones with length: " + someList.Count);
// for(int i = 0; i < someList.Count;i++){
// Debug.Log("Bone Name: " + someList[i].Data);
// }
bone = playerSkeleton.skeleton.FindBone("Head");
// I have tried this in several forms, using only bone.x, subtracting its parent and then the below.
// However they all seem incorrect.
transform.position = new Vector3(bone.X-bone.Parent.X-bone.Parent.Parent.X,
bone.Y-bone.Parent.Y-bone.Parent.Parent.Y,
transform.position.z);
Debug.Log("Bone information: " + bone.Data.Name);
Debug.Log("Bone X: " + bone.X);
Debug.Log("Bone Y: " + bone.Y);
Debug.Log("Bone WorldX: " + bone.WorldX);
Debug.Log("Bone WorldY: " + bone.WorldY);
Debug.Log("Bone Rotation: " + bone.Rotation);
Debug.Log("Bone world rotation: " + bone.WorldRotation);
Debug.Log("Bone worldscale x: " + bone.WorldScaleX);
Debug.Log("Bone worldscale y: " + bone.WorldScaleY);
Debug.Log("Bone Parent: " + bone.Parent);
Debug.Log("PARENT INFO: ");
Debug.Log("Parent X: " + bone.Parent.X);
Debug.Log("Parent Y: " + bone.Parent.Y);
Debug.Log("Parent worldX: " + bone.Parent.WorldX);
Debug.Log("Parent worldY: " + bone.Parent.WorldY);
Debug.Log("Parent of parent: " + bone.Parent.Parent.Data.Name);
Debug.Log("Parent root X: " + bone.Parent.Parent.X);
Debug.Log("Parent root Y: " + bone.Parent.Parent.Y);
Debug.Log("Parent root worldX: " + bone.Parent.Parent.WorldX);
Debug.Log("Parent root worldY: " + bone.Parent.Parent.WorldY);
Debug.Log("End of data!!!!!!!!!!" );
}
}