当前位置: 首页>>代码示例>>C#>>正文


C# Animator.SetIKRotation方法代码示例

本文整理汇总了C#中UnityEngine.Animator.SetIKRotation方法的典型用法代码示例。如果您正苦于以下问题:C# Animator.SetIKRotation方法的具体用法?C# Animator.SetIKRotation怎么用?C# Animator.SetIKRotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Animator的用法示例。


在下文中一共展示了Animator.SetIKRotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateAim

    // 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) );
    }
开发者ID:kamilion,项目名称:UNETMovement,代码行数:57,代码来源:NetworkedObserverSMMouseLook.cs

示例2: UpdateAim

	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));

	}
开发者ID:omgware,项目名称:UnityUnetMovement,代码行数:50,代码来源:MouseLook.cs


注:本文中的UnityEngine.Animator.SetIKRotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。