Пример #1
0
//---------------------------------------------------------------------MONO METHODS:

    void Start()
    {
        //TODO: add safeguards to ensure that the LeapHands don't go further than our avatar's reach;
        if (LeftTargetForearm != null && LeftElbow != null && LeftShoulder != null)
        {
            LeftShoulder.LocalLookRotation(LeftTargetForearm.Forward,
                                           LeftTargetForearm.Up);

            Vector3 armUp = Vector3.Cross(LeftShoulder.Forward, LeftTargetHand.forward);

            LeftElbow.LocalLookRotation(LeftTargetForearm.Forward, armUp);

            elbowToWristDistance = Vector3.Distance(LeftElbow.transform.position,
                                                    LeftTargetForearm.transform.position);
        }

        if (RightTargetForearm != null && RightElbow != null && RightShoulder != null)
        {
            RightShoulder.LocalLookRotation(RightTargetForearm.transform.forward
                                            , RightTargetForearm.transform.up);

            Vector3 armUp = Vector3.Cross(RightTargetForearm.transform.forward, RightShoulder.Forward);

            RightElbow.LocalLookRotation(RightTargetForearm.transform.forward, armUp);

            if (elbowToWristDistance == 0)
            {
                elbowToWristDistance = Vector3.Distance(RightElbow.transform.position,
                                                        RightTargetHand.position);
            }
        }
    }
Пример #2
0
    //private void Update()
    //{
    //    myLeft.transform.rotation = myLeft.LookRotation( LeftHandTarget.transform.rotation );
    //}

    void OnAnimatorIK()
    {
        if (Avatar)
        {
            if (HeadTarget != null)
            {
                var adjustedRot = myHead.LocalLookRotation(HeadTarget.rotation);

                Avatar.SetBoneLocalRotation(HumanBodyBones.Head, adjustedRot);
                //Avatar.SetBoneLocalRotation(HumanBodyBones.Head,adjustedRot);
            }
            if (LeftHandTarget != null)
            {
                //Avatar.SetIKPositionWeight( AvatarIKGoal.LeftHand, LookWeight );
                //Avatar.SetIKRotationWeight( AvatarIKGoal.LeftHand, RotationWeight );
                Avatar.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
                Avatar.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);


                Avatar.SetIKPosition(AvatarIKGoal.LeftHand, LeftHandTarget.position);
                Avatar.SetIKRotation(AvatarIKGoal.LeftHand, LeftHandTarget.rotation);
            }
            if (RightHandTarget != null)
            {
                Avatar.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
                Avatar.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
                //Avatar.SetIKPositionWeight( AvatarIKGoal.RightHand, LookWeight );
                //Avatar.SetIKRotationWeight( AvatarIKGoal.RightHand, RotationWeight );

                Avatar.SetIKPosition(AvatarIKGoal.RightHand, RightHandTarget.position);
                Avatar.SetIKRotation(AvatarIKGoal.RightHand, RightHandTarget.rotation);
            }
        }
    }