Document example dont Work !!!

hi all
i have a humanoid character with a configured Avatar.
i create c# Script and copy all code in this page and attach to character.

using UnityEngine;
using System;
using System.Collections;

[RequireComponent(typeof(Animator))]  

public class IKCtrl : MonoBehaviour {

	protected Animator animator;

	public bool ikActive = false;
	public Transform rightHandObj = null;

	void Start () 
	{
		animator = GetComponent<Animator>();
	}

        //a callback for calculating IK
	void OnAnimatorIK()
	{
	      if(animator) {

                        //if the IK is active, set the position and rotation directly to the goal. 
			if(ikActive) {

                                //weight = 1.0 for the right hand means position and rotation will be at the IK goal (the place the character wants to grab)
				animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1.0f);
				animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1.0f);

			        //set the position and the rotation of the right hand where the external object is
				if(rightHandObj != null) {
					animator.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position);
					animator.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation);
				}					

			}

                        //if the IK is not active, set the position and rotation of the hand back to the original position
			else {			
				animator.SetIKPositionWeight(AvatarIKGoal.RightHand,0);
				animator.SetIKRotationWeight(AvatarIKGoal.RightHand,0);				
			}
		}
	}	  
}

and create a Sphere in scene and set to “Right Hand Obj”
when play game don’t work for me !
why ?!

tanx all

OnAnimatorIK has a layer index parameter, but you leave that away.

you mean
OnAnimatorIK function and parametere has :

SetIKPositionWeight
SetIKRotationWeight
SetIKPosition
SetIKRotation

?

void OnAnimatorIK(int layerIndex) {
    ....
}

dont work !

using UnityEngine;
using System;
using System.Collections;

[RequireComponent(typeof(Animator))]  

public class IKCtrl : MonoBehaviour {

	protected Animator animator;

	public bool ikActive = false;
	public Transform rightHandObj = null;

	void Start () 
	{
		animator = GetComponent<Animator>();
	}

        //a callback for calculating IK
	void OnAnimatorIK(int layerIndex)
	{
	      if(animator) {

                        //if the IK is active, set the position and rotation directly to the goal. 
			if(ikActive) {

                                //weight = 1.0 for the right hand means position and rotation will be at the IK goal (the place the character wants to grab)
				animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1.0f);
				animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1.0f);

			        //set the position and the rotation of the right hand where the external object is
				if(rightHandObj != null) {
					animator.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position);
					animator.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation);
				}					

			}

                        //if the IK is not active, set the position and rotation of the hand back to the original position
			else {			
				animator.SetIKPositionWeight(AvatarIKGoal.RightHand,0);
				animator.SetIKRotationWeight(AvatarIKGoal.RightHand,0);				
			}
		}
	}	  
}

Did you do some basic debugging by placing Debug.Log (“…”) to see if it is executed at all?

no

You have to open the Animator (Windows > Animator) > Base Layer > IK Pass = true.

http://forum.unity3d.com/threads/159038-Problems-with-OnAnimatorIK