- Modifié
[UNITY] Position / rotate a bone through code?
Hi, I'm having some trouble rotating a my head bone through code. At the moment I'm trying this in Update and LateUpdate:
headBone.Rotation = 180; // for testing
Followed by various combinations of:
skeleton.UpdateWorldTransform();
skeleton.Update(0f);
skeletonAnimation.state.Update(0f);
skeletonAnimation.UpdateSkeleton(0f);
But none of them work. However if I try:
skeletonAnimation.state.SetAnimation(0, "run", true);
after setting the rotation then the head bone is rotated to 180 degrees (but obviously the animation keeps restarting over and over)
I've looked in SkeletonComponent.Update and really seems I should have to position the bones somewhere around line 129 but obviously there's no hook for that.
Somebody must have solved this - any help greatly appreciated!
How I solved it:
Duplicated SkeletonAnimation and renamed as CharacterSpineAnimator, still extending SkeletonComponent. Used that instead of SkeletonAnimation and added in my own code.
Had to also make a duplicate of SkeletonAnimationInspector and change all the refs that pointed to SkeletonAnimation so that it showed with the right controls in the inspector.
This wasn't how I imagined I would have done it but it seems to work. Is this about right?
Looks like we can continue discussion here:
viewtopic.php?p=8660#p8660