Esempio n. 1
0
        void rotateShoulderUp(Transform shoulderSide, ArmTransforms arm, Transform targetHand,
                              Vector3 initialShoulderLocalPos, float angleSign)
        {
            Vector3 initialShoulderPos = shoulder.transform.TransformPoint(initialShoulderLocalPos);
            Vector3 handShoulderOffset = targetHand.position - initialShoulderPos;
            float   armLength          = arm.armLength;

            Vector3 targetAngle = Vector3.zero;

            float forwardDistanceRatio = Vector3.Dot(handShoulderOffset, shoulder.transform.forward) / armLength;
            float upwardDistanceRatio  = Vector3.Dot(handShoulderOffset, shoulder.transform.up) / armLength;

            if (forwardDistanceRatio > 0f)
            {
                targetAngle.y = Mathf.Clamp((forwardDistanceRatio - 0.5f) * distinctShoulderRotationMultiplier, 0f,
                                            distinctShoulderRotationLimitForward);
            }
            else
            {
                targetAngle.y = Mathf.Clamp(-(forwardDistanceRatio + 0.08f) * distinctShoulderRotationMultiplier * 10f,
                                            -distinctShoulderRotationLimitBackward, 0f);
            }

            targetAngle.z = Mathf.Clamp(-(upwardDistanceRatio - 0.5f) * distinctShoulderRotationMultiplier,
                                        -distinctShoulderRotationLimitUpward, 0f);

            shoulderSide.localEulerAngles = targetAngle * angleSign;
        }
Esempio n. 2
0
 void Awake()
 {
     if (leftArm == null)
     {
         leftArm = Instantiate(leftArmDummy, leftShoulderAnchor.position, leftShoulderAnchor.rotation, leftShoulderAnchor);
         var armIk = leftArm.GetComponentInChildren <VRArmIK>();
         armIk.shoulder      = this;
         armIk.shoulderPoser = GetComponent <ShoulderPoser>();
         armIk.target        = armIk.shoulderPoser.avatarTrackingReferences.leftHand.transform;
     }
     if (rightArm == null)
     {
         rightArm = Instantiate(rightArmDummy, leftShoulderAnchor.position, rightShoulderAnchor.rotation, rightShoulderAnchor);
         var armIk = rightArm.GetComponentInChildren <VRArmIK>();
         armIk.shoulder      = this;
         armIk.shoulderPoser = GetComponent <ShoulderPoser>();
         armIk.target        = armIk.shoulderPoser.avatarTrackingReferences.rightHand.transform;
     }
 }