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