The problem with OnAnimatorIK()

hi all
I have an object, when this object to child of Player .
i want access to child of object.
and i want access to child transform.position of child with this code:

gameObject.FindGameObjectWithTag("LH").transform.position

this code attach to Player:

function OnAnimatorIK()
{
	//for Left hand
	//postion Left hand
	animator.SetIKPositionWeight(AvatarIKGoal.LeftHand , weightForLHPosition);
	animator.SetIKPosition(AvatarIKGoal.LeftHand , gameObject.FindGameObjectWithTag("LH").transform.position);
	// rotation Left Hand
	animator.SetIKRotationWeight(AvatarIKGoal.LeftHand , weighForLHRotation);
	animator.SetIKRotation(AvatarIKGoal.LeftHand , gameObject.FindGameObjectWithTag("LH").transform.rotation);
	
// for Right Hand
	// position Righ hand
	animator.SetIKPositionWeight(AvatarIKGoal.RightHand , weighforRHPostion);
	animator.SetIKPosition(AvatarIKGoal.RightHand , gameObject.FindGameObjectWithTag("RH").transform.position);
	// rotaion Righ Hand
	animator.SetIKRotationWeight(AvatarIKGoal.RightHand , weighforRHRotation);
	animator.SetIKRotation(AvatarIKGoal.RightHand , gameObject.FindGameObjectWithTag("RH").transform.rotation);
	
}

but don’t work !

any body help me ?

Hey Djary,

This script must be on the same component as your Animator in order to receive the OnAnimatorIK callback. I have cleaned up a couple things in the script and moved the tag finds to public Transform variables (make sure that you assign the left and right hands in the inspector).

var leftHand : Transform;
var rightHand : Transform;

function OnAnimatorIK(layerIndex : int)
{
    //postion Left hand
    animator.SetIKPositionWeight(AvatarIKGoal.LeftHand , weightForLHPosition);
    animator.SetIKPosition(AvatarIKGoal.LeftHand , leftHand.position);

    // rotation Left Hand
    animator.SetIKRotationWeight(AvatarIKGoal.LeftHand , weighForLHRotation);
    animator.SetIKRotation(AvatarIKGoal.LeftHand , leftHand.rotation);


    // position Right hand
    animator.SetIKPositionWeight(AvatarIKGoal.RightHand , weighforRHPostion);
    animator.SetIKPosition(AvatarIKGoal.RightHand , rightHand.position);

    // rotaion Right Hand
    animator.SetIKRotationWeight(AvatarIKGoal.RightHand , weighforRHRotation);
    animator.SetIKRotation(AvatarIKGoal.RightHand , rightHand.rotation);
}
  • I don’t do any UnityScript programming, code may contain errors.

tanx man but my player have many guns
my guns have 2 child for hands : LH and RH
when player pickup guns ,player has parent of gun (GameObject(s))
i want , when gun child of parent (Player) hand attach to LH and RH