SetIKRotationWeight() 공개 메소드

public SetIKRotationWeight ( AvatarIKGoal goal, float value ) : void
goal AvatarIKGoal
value float
리턴 void
예제 #1
0
	void UpdateAim(Animator animator){

		//Need to discard previosly made rotation in order to get correct final hands position
		_spine.localRotation *= Quaternion.Inverse(_spineDeltaRotation);
		_chest.localRotation *= Quaternion.Inverse(_chestDeltaRotation);

		//Aiming
		Vector3 originalCamPos = _components.bodyController._camera.transform.position;
		Quaternion originalCamRot = _components.bodyController._camera.transform.rotation;
		_components.bodyController._camera.transform.position = _components.inventory._availableItems [_components.inventory._slots [_slot]].Aimpoint.position;
		_components.bodyController._camera.transform.rotation = _components.inventory._availableItems [_components.inventory._slots [_slot]].Aimpoint.rotation;
		//Translating chest position and rotation to camera space
		Vector3 localChestPosition = _components.bodyController._camera.transform.InverseTransformPoint (_chest.position);
		Vector3 localChestUp = _components.bodyController._camera.transform.InverseTransformDirection (_chest.up);
		Vector3 localChestForward = _components.bodyController._camera.transform.InverseTransformDirection (_chest.forward);
		//Reverting to original camera position and rotation
		_components.bodyController._camera.transform.position = originalCamPos;
		_components.bodyController._camera.transform.rotation = originalCamRot;
		//Setting chest to target position
		Vector3 targetChestPos = _components.bodyController._camera.transform.TransformPoint (localChestPosition);
		Vector3 targetChestUp = _components.bodyController._camera.transform.TransformDirection (localChestUp);
		Vector3 targetChestForward = _components.bodyController._camera.transform.TransformDirection (localChestForward);
		Vector3 originalChestPos = _chest.position;
		Quaternion originalChestRot = _chest.rotation;
		_chest.position = Vector3.Lerp(_chest.position,targetChestPos,_power);
		_chest.rotation = Quaternion.Slerp(_chest.rotation,Quaternion.LookRotation (targetChestForward, targetChestUp),_power);
		//Setting IK targets
		Vector3 leftHandPos = _leftHand.position;
		Vector3 rightHandPos = _rightHand.position;
		Quaternion leftHandRot = _leftHand.rotation;
		Quaternion rightHandRot = _rightHand.rotation;
		
		//Reseting chest position and rotation
		_chest.position = originalChestPos;
		_chest.rotation = originalChestRot;
		
		
		
		//IK
		animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, _power);
		animator.SetIKPositionWeight (AvatarIKGoal.RightHand, _power);
		animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, _power);
		animator.SetIKRotationWeight (AvatarIKGoal.RightHand, _power);
		
		animator.SetIKPosition (AvatarIKGoal.LeftHand, leftHandPos);
		animator.SetIKPosition (AvatarIKGoal.RightHand, rightHandPos);
		animator.SetIKRotation (AvatarIKGoal.LeftHand, leftHandRot * Quaternion.Euler(0,-90,0));
		animator.SetIKRotation (AvatarIKGoal.RightHand, rightHandRot * Quaternion.Euler(0,90,0));

	}
    // Update the aim target.
    void UpdateAim (Animator animator) {
        // This is only called if we're actually supposed to be aiming.

        // Need to discard previously made rotation in order to get the correct final position of the hands around a weapon.
        m_spine.localRotation *= Quaternion.Inverse(m_spineDeltaRotation);
        m_chest.localRotation *= Quaternion.Inverse(m_chestDeltaRotation);

        // Aiming.
        Vector3 originalCamPos = m_components.fpcamera.transform.position;
        Quaternion originalCamRot = m_components.fpcamera.transform.rotation;
        m_components.fpcamera.transform.position = m_components.inventory.m_availableItems [m_components.inventory.m_slots [m_slot] ].m_Aimpoint.position;
        m_components.fpcamera.transform.rotation = m_components.inventory.m_availableItems [m_components.inventory.m_slots [m_slot] ].m_Aimpoint.rotation;

        // Translating chest position and rotation to camera space.
        Vector3 localChestPosition = m_components.fpcamera.transform.InverseTransformPoint (m_chest.position);
        Vector3 localChestUp = m_components.fpcamera.transform.InverseTransformDirection (m_chest.up);
        Vector3 localChestForward = m_components.fpcamera.transform.InverseTransformDirection (m_chest.forward);

        // Reverting to original camera position and rotation.
        m_components.fpcamera.transform.position = originalCamPos;
        m_components.fpcamera.transform.rotation = originalCamRot;

        // Setting chest to target position.
        Vector3 targetChestPos = m_components.fpcamera.transform.TransformPoint (localChestPosition);
        Vector3 targetChestUp = m_components.fpcamera.transform.TransformDirection (localChestUp);
        Vector3 targetChestForward = m_components.fpcamera.transform.TransformDirection (localChestForward);

        Vector3 originalChestPos = m_chest.position;
        Quaternion originalChestRot = m_chest.rotation;
        m_chest.position = Vector3.Lerp (m_chest.position, targetChestPos, m_progress);
        m_chest.rotation = Quaternion.Slerp (m_chest.rotation, Quaternion.LookRotation (targetChestForward, targetChestUp), m_progress);
        
        // Setting IK targets.
        Vector3 leftHandPos = m_leftHand.position;
        Vector3 rightHandPos = m_rightHand.position;

        Quaternion leftHandRot = m_leftHand.rotation;
        Quaternion rightHandRot = m_rightHand.rotation;
        
        // Reset of chest position and rotation.
        m_chest.position = originalChestPos;
        m_chest.rotation = originalChestRot;
        
        // Do Inverse Kinematics.
        animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, m_progress);
        animator.SetIKPositionWeight (AvatarIKGoal.RightHand, m_progress);

        animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, m_progress);
        animator.SetIKRotationWeight (AvatarIKGoal.RightHand, m_progress);
        
        animator.SetIKPosition (AvatarIKGoal.LeftHand, leftHandPos);
        animator.SetIKPosition (AvatarIKGoal.RightHand, rightHandPos);

        animator.SetIKRotation (AvatarIKGoal.LeftHand, leftHandRot * Quaternion.Euler(0, -90, 0) );
        animator.SetIKRotation (AvatarIKGoal.RightHand, rightHandRot * Quaternion.Euler(0, 90, 0) );
    }
        private void OnAnimatorIK(int layerIndex)
        {
            if (animator != null)
            {
                animator.SetLookAtWeight(lookAtWeight, lookAtBodyWeight, lookAtHeadWeight, lookAtEyesWeight, lookAtClampWeight);
                animator.SetLookAtPosition(lookAtPosition);

                animator.SetIKPositionWeight(AvatarIKGoal.RightHand, rightHandPosWeight);
                animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, leftHandPosWeight);
                animator.SetIKPositionWeight(AvatarIKGoal.RightFoot, rightFootPosWeight);
                animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootPosWeight);

                animator.SetIKRotationWeight(AvatarIKGoal.RightHand, rightHandRotWeight);
                animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, leftHandRotWeight);
                animator.SetIKRotationWeight(AvatarIKGoal.RightFoot, rightFootRotWeight);
                animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootRotWeight);

                animator.SetIKHintPositionWeight(AvatarIKHint.RightElbow, rightElbowPosWeight);
                animator.SetIKHintPositionWeight(AvatarIKHint.LeftElbow, leftElbowPosWeight);
                animator.SetIKHintPositionWeight(AvatarIKHint.RightKnee, rightKneePosWeight);
                animator.SetIKHintPositionWeight(AvatarIKHint.LeftKnee, leftKneePosWeight);

                animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandPos);
                animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandPos);
                animator.SetIKPosition(AvatarIKGoal.RightFoot, rightFootPos);
                animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootPos);

                animator.SetIKHintPosition(AvatarIKHint.RightElbow, rightElbowPos);
                animator.SetIKHintPosition(AvatarIKHint.LeftElbow, leftElbowPos);
                animator.SetIKHintPosition(AvatarIKHint.RightKnee, rightKneePos);
                animator.SetIKHintPosition(AvatarIKHint.LeftKnee, leftKneePos);

                animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandRot);
                animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandRot);
                animator.SetIKRotation(AvatarIKGoal.RightFoot, rightFootRot);
                animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootRot);

                internalLeftFootPos  = animator.GetIKPosition(AvatarIKGoal.LeftFoot);
                internalRightFootPos = animator.GetIKPosition(AvatarIKGoal.RightFoot);
                internalLeftHandPos  = animator.GetIKPosition(AvatarIKGoal.LeftHand);
                internalRightHandPos = animator.GetIKPosition(AvatarIKGoal.RightHand);

                internalLeftFootRot  = animator.GetIKRotation(AvatarIKGoal.LeftFoot);
                internalRightFootRot = animator.GetIKRotation(AvatarIKGoal.RightFoot);
                internalLeftHandRot  = animator.GetIKRotation(AvatarIKGoal.LeftHand);
                internalRightHandRot = animator.GetIKRotation(AvatarIKGoal.RightHand);

                internalLeftKneePos   = animator.GetIKHintPosition(AvatarIKHint.LeftKnee);
                internalRightKneePos  = animator.GetIKHintPosition(AvatarIKHint.RightKnee);
                internalLeftElbowPos  = animator.GetIKHintPosition(AvatarIKHint.LeftElbow);
                internalRightElbowPos = animator.GetIKHintPosition(AvatarIKHint.RightElbow);


                internalLeftFootPosWeight  = animator.GetIKPositionWeight(AvatarIKGoal.LeftFoot);
                internalRightFootPosWeight = animator.GetIKPositionWeight(AvatarIKGoal.RightFoot);
                internalLeftHandPosWeight  = animator.GetIKPositionWeight(AvatarIKGoal.LeftHand);
                internalRightHandPosWeight = animator.GetIKPositionWeight(AvatarIKGoal.RightHand);

                internalLeftFootRotWeight  = animator.GetIKRotationWeight(AvatarIKGoal.LeftFoot);
                internalRightFootRotWeight = animator.GetIKRotationWeight(AvatarIKGoal.RightFoot);
                internalLeftHandRotWeight  = animator.GetIKRotationWeight(AvatarIKGoal.LeftHand);
                internalRightHandRotWeight = animator.GetIKRotationWeight(AvatarIKGoal.RightHand);

                internalLeftKneeWeight   = animator.GetIKHintPositionWeight(AvatarIKHint.LeftKnee);
                internalRightKneeWeight  = animator.GetIKHintPositionWeight(AvatarIKHint.RightKnee);
                internalLeftElbowWeight  = animator.GetIKHintPositionWeight(AvatarIKHint.LeftElbow);
                internalRightElbowWeight = animator.GetIKHintPositionWeight(AvatarIKHint.RightElbow);
            }
        }