UnityEngine.Animator.SetIKRotation C# (CSharp) Method

SetIKRotation() public method

public SetIKRotation ( AvatarIKGoal goal, Quaternion goalRotation ) : void
goal AvatarIKGoal
goalRotation Quaternion
return void
		public void SetIKRotation(AvatarIKGoal goal, Quaternion goalRotation){}
		private static void INTERNAL_CALL_SetIKRotation(Animator self, AvatarIKGoal goal, ref Quaternion goalRotation){}

Usage Example

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

	}
All Usage Examples Of UnityEngine.Animator::SetIKRotation
Animator