Hi,
I'm using the event UpdateLocal to make an arm IK follow a transform which holds a weapon. That works great and the weapon is rotated to aim towards the mouse in another script.
However I also want to rotate the hand, to match the rotation of the weapon. I tried bone.rotation, and tried in both UpdateLocal and UpdateComplete but it doesn't seem to change anything. Is the IK overriding it? Can I apply rotation after the IK has been applied to the bones?
The armIK constraint in Spine is setup like this:
Parent: armUpL
Child: armDownL
Target: IKLeft
The hand (handL) is automatically rotated and matches armDownL, but I'd like to rotate this manually.
Currently I'm just using floats to set the rotation to make sure it works. Here's my code. Thank you in advance for any ideas! 🙂
public class SpineBoneTargetController : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[SpineBone(dataField: "skeletonAnimation")]
public string armIKR;
[SpineBone(dataField: "skeletonAnimation")]
public string armIKL;
[SpineBone(dataField: "skeletonAnimation")]
public string handR;
[SpineBone(dataField: "skeletonAnimation")]
public string handL;
Bone boneR;
Bone boneL;
Bone handBoneR;
Bone handBoneL;
public Transform followTransformR;
public Transform followTransformL;
public float handRRotation;
public float handLRotation;
void OnValidate() {
if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
}
void Start() {
// Connect bones till selected SpineBone
boneR = skeletonAnimation.Skeleton.FindBone(armIKR);
boneL = skeletonAnimation.Skeleton.FindBone(armIKL);
handBoneR = skeletonAnimation.Skeleton.FindBone(handR);
handBoneL = skeletonAnimation.Skeleton.FindBone(handL);
skeletonAnimation.UpdateLocal += UpdateLocal;
skeletonAnimation.UpdateComplete += UpdateComplete;
}
void UpdateComplete(ISkeletonAnimation s) {
handBoneR.rotation = handRRotation;
handBoneL.rotation = handLRotation;
}
// Is run after animation complete, to manually update bone
void UpdateLocal(ISkeletonAnimation s) {
// Set weapon position to WeaponAttachment
if (followTransformR != null) {
boneR.SetLocalPosition(transform.InverseTransformPoint(followTransformR.position));
}
// If GripL exists, set left arm IK
if (followTransformL != null) {
boneL.SetLocalPosition(transform.InverseTransformPoint(followTransformL.position));
}
}
}