protected virtual void UpdateIKAdjust(bool isUsingLeftHand) { vWeaponIKAdjust weaponIKAdjust = shooterManager.CurrentWeaponIK; if (!weaponIKAdjust || IsAnimatorTag("IgnoreIK")) { weaponIKWeight = 0; return; } weaponIKWeight = Mathf.Lerp(weaponIKWeight, IsReloading || IsEquipping ? 0 : 1, 25f * Time.deltaTime); if (weaponIKWeight <= 0) { return; } // create left arm ik solver if equal null if (LeftIK == null) { LeftIK = new vIKSolver(animator, AvatarIKGoal.LeftHand); LeftIK.UpdateIK(); } if (RightIK == null) { RightIK = new vIKSolver(animator, AvatarIKGoal.RightHand); RightIK.UpdateIK(); } if (isUsingLeftHand) { ApplyOffsets(weaponIKAdjust, LeftIK, RightIK); } else { ApplyOffsets(weaponIKAdjust, RightIK, LeftIK); } }
void ApplyOffsets(IKAdjust currentIKAdjust, vIKSolver weaponArm, vIKSolver supportWeaponArm) { currentIKAdjust.supportHandOffset.position = supportWeaponArm.endBoneOffset.localPosition; currentIKAdjust.supportHandOffset.eulerAngles = supportWeaponArm.endBoneOffset.localEulerAngles; currentIKAdjust.supportHintOffset.position = supportWeaponArm.middleBoneOffset.localPosition; currentIKAdjust.supportHintOffset.eulerAngles = supportWeaponArm.middleBoneOffset.localEulerAngles; currentIKAdjust.weaponHandOffset.position = weaponArm.endBoneOffset.localPosition; currentIKAdjust.weaponHandOffset.eulerAngles = weaponArm.endBoneOffset.localEulerAngles; currentIKAdjust.weaponHintOffset.position = weaponArm.middleBoneOffset.localPosition; currentIKAdjust.weaponHintOffset.eulerAngles = weaponArm.middleBoneOffset.localEulerAngles; ik.ApplyModifiedProperties(); EditorUtility.SetDirty(ik.targetObject); }
protected virtual void UpdateLeftIK() { if (!shooterManager || !shooterManager.rWeapon || !shooterManager.rWeapon.gameObject.activeInHierarchy || !shooterManager.useLeftIK) { return; } bool useIkOnIdle = cc.input.magnitude < 0.1f ? shooterManager.rWeapon.useIkOnIdle : true; bool useIkStrafeMoving = new Vector2(animator.GetFloat("InputVertical"), animator.GetFloat("InputHorizontal")).magnitude > 0.1f && cc.isStrafing ? shooterManager.rWeapon.useIkOnStrafe : true; bool useIkFreeMoving = animator.GetFloat("InputVertical") > 0.1f && !cc.isStrafing ? shooterManager.rWeapon.useIkOnFree : true; bool useIkAttacking = isAttacking ? shooterManager.rWeapon.useIkAttacking : true; bool useIkConditions = !(!useIkOnIdle || !useIkStrafeMoving || !useIkFreeMoving || !useIkAttacking); // create left arm ik solver if equal null if (leftIK == null) { leftIK = new vIKSolver(animator, AvatarIKGoal.LeftHand); } if (leftIK != null) { // control weight of ik if (shooterManager.rWeapon && shooterManager.rWeapon.handIKTarget && Time.timeScale > 0 && !isReloading && !cc.actions && !cc.customAction && !isEquipping && (cc.isGrounded || (isAiming || aimTimming > 0f)) && !cc.lockMovement && useIkConditions) { lIKWeight = Mathf.Lerp(lIKWeight, 1, 10f * Time.deltaTime); } else { lIKWeight = Mathf.Lerp(lIKWeight, 0, 10f * Time.deltaTime); } if (lIKWeight <= 0) { return; } // update IK leftIK.SetIKWeight(lIKWeight); if (shooterManager && shooterManager.rWeapon && shooterManager.rWeapon.handIKTarget) { var _offset = (shooterManager.rWeapon.handIKTarget.forward * shooterManager.ikPositionOffset.z) + (shooterManager.rWeapon.handIKTarget.right * shooterManager.ikPositionOffset.x) + (shooterManager.rWeapon.handIKTarget.up * shooterManager.ikPositionOffset.y); leftIK.SetIKPosition(shooterManager.rWeapon.handIKTarget.position + _offset); var _rotation = Quaternion.Euler(shooterManager.ikRotationOffset); leftIK.SetIKRotation(shooterManager.rWeapon.handIKTarget.rotation * _rotation); } } }
protected virtual void ApplyOffsets(vWeaponIKAdjust weaponIKAdjust, vIKSolver weaponHand, vIKSolver supportHand) { bool isValid = weaponIKAdjust != null; weaponHand.SetIKWeight(weaponIKWeight); IKAdjust ikAdjust = isValid ? weaponIKAdjust.GetIKAdjust(isAiming, isCrouching) : null; //Apply Offset to Weapon Arm ApplyOffsetToTargetBone(isValid ? ikAdjust.weaponHandOffset : null, weaponHand.endBoneOffset, isValid); ApplyOffsetToTargetBone(isValid ? ikAdjust.weaponHintOffset : null, weaponHand.middleBoneOffset, isValid); //Apply offset to Support Weapon Arm ApplyOffsetToTargetBone(isValid ? ikAdjust.supportHandOffset : null, supportHand.endBoneOffset, isValid); ApplyOffsetToTargetBone(isValid ? ikAdjust.supportHintOffset : null, supportHand.middleBoneOffset, isValid); //Convert Animatorion To IK with offsets applied if (isValid) { weaponHand.AnimationToIK(); } }
protected virtual void UpdateLeftIK(bool isUsingLeftHand = false) { var weapon = shooterManager.rWeapon ? shooterManager.rWeapon : shooterManager.lWeapon; if (!shooterManager || !weapon || !weapon.gameObject.activeInHierarchy || !shooterManager.useLeftIK) { return; } if (animator.GetCurrentAnimatorStateInfo(6).IsName("Shot Fire") && weapon.disableIkOnShot) { lIKWeight = 0; return; } bool useIkConditions = false; var animatorInput = cc.isStrafing ? new Vector2(animator.GetFloat("InputVertical"), animator.GetFloat("InputHorizontal")).magnitude : animator.GetFloat("InputVertical"); if (!isAiming && !isAttacking) { if (animatorInput < 0.1f) { useIkConditions = weapon.useIkOnIdle; } else if (cc.isStrafing) { useIkConditions = weapon.useIkOnStrafe; } else { useIkConditions = weapon.useIkOnFree; } } else if (isAiming && !isAttacking) { useIkConditions = weapon.useIKOnAiming; } else if (isAttacking) { useIkConditions = weapon.useIkAttacking; } // create left arm ik solver if equal null if (leftIK == null) { leftIK = new vIKSolver(animator, AvatarIKGoal.LeftHand); } if (rightIK == null) { rightIK = new vIKSolver(animator, AvatarIKGoal.RightHand); } vIKSolver targetIK = null; if (isUsingLeftHand) { targetIK = rightIK; } else { targetIK = leftIK; } if (targetIK != null) { if (isUsingLeftHand) { ikRotationOffset = shooterManager.ikRotationOffsetR; ikPositionOffset = shooterManager.ikPositionOffsetR; } else { ikRotationOffset = shooterManager.ikRotationOffsetL; ikPositionOffset = shooterManager.ikPositionOffsetL; } // control weight of ik if (weapon && weapon.handIKTarget && Time.timeScale > 0 && !isReloading && !cc.actions && !cc.customAction && !isEquipping && (cc.isGrounded || (isAiming || aimTimming > 0f)) && !cc.lockMovement && useIkConditions) { lIKWeight = Mathf.Lerp(lIKWeight, 1, 10f * Time.deltaTime); } else { lIKWeight = Mathf.Lerp(lIKWeight, 0, 10f * Time.deltaTime); } if (lIKWeight <= 0) { return; } // update IK targetIK.SetIKWeight(lIKWeight); if (shooterManager && weapon && weapon.handIKTarget) { var _offset = (weapon.handIKTarget.forward * ikPositionOffset.z) + (weapon.handIKTarget.right * ikPositionOffset.x) + (weapon.handIKTarget.up * ikPositionOffset.y); targetIK.SetIKPosition(weapon.handIKTarget.position + _offset); var _rotation = Quaternion.Euler(ikRotationOffset); targetIK.SetIKRotation(weapon.handIKTarget.rotation * _rotation); } } }
public IKSolverEditorHelper(vIKSolver iKSolver) { this.iKSolver = iKSolver; }