I have an ogre model using skeletal animation, and during a looping animation (like an idle, where it’s breathing) I want its head to turn independently of its body and track the main character. So that turning needs to be in script.
One way to do this would be to augment the animated transform of the head node in the hierarchy with a script-supplied transform (which would be propogated to decendants), but I see no way of doing this.
I’m guessing the transforms in the skeletal hierarchy are computed from the skinning data, and if they are all pre-computed, then I probably can’t intercept them in script.
Does anyone know how this can be done?
Thank you for any suggestions.
Unity simply animates the transforms which make up the bones, the skinned mesh then reads the position/rotation/scale from the Transforms when skinning the mesh.
So you can just modify the transforms in any way you like, which will then drive the skinned mesh. This is eg. how ragdolls work.
So in your case just set transform.rotation to some value or use transform.LookAt. Note that animation is performed after Update and before LateUpdate, thus it is a good idea to just set the transform rotation in LateUpdate and not in Update.
Thanks for the explanation, Joachim. Putting my code in LateUpdate() solved the problem–my transforms were probably being overwritten by the “animation advancement” between Update() and LateUpdate().