How can I set avatar's particular joint angle via script (mecanim)?

Hello,

I’m new to Unity and I’m working on project with mecanim avatar walk in combination with Kinect. Maybe I’m just missing something very obvious, but I’ll be glad if someone can explain to me cause it’s driving me crazy. I’m using scene from mecanim sample and trying to access joints in BotControlScript through Animator or getComponent.

The thing is, I need to access avatar’s leg joints and set their angle manually in script, in order to set avatar’s pose or even influence walk in progress.

I’ve searched forums and Unity documentation and found that I need something like Animator.SetIKPosition, but in that case Unity is doing movement to point for me and I need to edit particular joints separately.

If you want to override the joint rotation set by Mecanim you need to do so in LateUpdate(). E.g. to make the character’s head always look towards camera, you could do something like:

void LateUpdate() {	
    Transform head = transform.Find("Armature/mixamorig_Hips/mixamorig_Spine/mixamorig_Spine1/mixamorig_Spine2/mixamorig_Neck/mixamorig_Head");		
    Vector3 targetPos = GameObject.Find("Main Camera").transform.position;
    head.rotation = Quaternion.LookRotation(targetPos - head.position);
}