- Home /
manually control bone while animations handle skeleton
This is my first foray into mechanim, and I'm liking it so far! I'm looking into one situation that I'm not sure how to tackle:
I have a skeleton that is being controlled by animations, but at certain points I'd like to free up the hands and have them directly controlled by skeleton tracking (using zigfu, which is awesome).
I'm not sure how to override the animations in order to manually dictate (through zigfu) the locations of each targeted transform.
I'm currently looking into body masks, but I might need something else in conjunction, since even an arm body mask would still attempt to control the arms via animation.
Any ideas in which direction I should be researching? Thank you in advance
i have not played with mechanim yet and dont know zigfu, but i would just move/rotate the bone directly inside LateUpdate().
yep! this seems to work. if you ever have need of skeleton tracking via kinect, i'd highly recommend zigfu. I've only played with it a very little bit, but so far it seems really useful and very good and detecting and holding onto skeletons
Answer by zombience · Feb 05, 2013 at 07:15 PM
I've actually found a better way to do this. there is a method, OnAnimatorIK(int layerIndex) that gives access to the animator at the time that it is computing the IK weights and targets.
You can set targets and weight for parts of the skeleton, and the animator will work with you to move the desired bones to the IK targets. I've implemented this with a zigFu input, and it works really really well. The animator still handles all bone lengths and relationships appropriately, whereas manually overriding bone transform locations in LateUpdate() ignores the bone and muscle relationships and therefore has really awful results if you don't write your own custom bone management.
So, a code snipped like this works wonders:
void OnAnimatorIK(int layerIndex)
{
if(avatar)
if(ikActive)
{ avatar.SetIKPositionWeight(AvatarIKGoal.LeftFoot,leftFootWeightPosition);
avatar.SetIKRotationWeight(AvatarIKGoal.LeftFoot,leftFootWeightRotation);
}
}
What should avatar be ? ikActive is bool i think but what do we do with avatar ? Same ?
Answer by MalikDrako · Jan 10, 2013 at 12:55 AM
Take a look at http://docs.unity3d.com/Documentation/Manual/ExecutionOrder.html
LateUpdate() happens after animations have been applied and before rendering, so you can manually specify the locations of the transforms there. Just remember that any changes you make will be overridden for the next LateUpdate(), so you either need to specify an absolute position, or store a copy of the position that you can specify the position relative to
thank you. i've switched up my scripts to do this and it seems to work well so far. this does seem like a bit of a brute force method. the animations are still processing movement and position, and I'm just overriding that with a later call. I'll work with this for now, but keep searching for a more elegant method. Thanks!
Your answer
Follow this Question
Related Questions
Imported Blender Animations not Working 2 Answers
Continuously Play Animation Forwards and Backwards with Mechanim 0 Answers
Animation Transitions, Mechanim, Animator Overview Gizmos. 0 Answers
How to nest Animation file in an Animation Controller? 1 Answer
Why do my animations only play once? 1 Answer