/// <summary> /// Apply IK to the limb. /// </summary> public void SetIK(Limbs limb, IKWeight ikData) { switch (limb) { case Limbs.LeftHand: leftHandIK = ikData; break; case Limbs.RightHand: rightHandIK = ikData; break; case Limbs.LeftFoot: leftFootIK = ikData; break; case Limbs.RightFoot: rightFootIK = ikData; break; } }
private void Update() { if (player.Character == null || !animator) { return; } if (climbingTime > 0) { climbingTime -= Time.deltaTime; } isGroundedValue = Mathf.Lerp(isGroundedValue, player.Character.isGrounded ? 1 : 0, Time.deltaTime * 4); isGrounded = isGroundedValue > 0.5f || player.Character.isGrounded; float targetVelocity = player.Character.steppingUp ? 0.5f : player.Character.horizontalVelocity.magnitude / player.Character.maxSpeed; if (player.Character.MoveDirection.magnitude <= 0.01f) { targetVelocity = 0; } velocity = Mathf.Lerp(velocity, targetVelocity, Time.deltaTime * speedSmoothing); if (!string.IsNullOrEmpty(speedParameter)) { animator.SetFloat(speedParameter, velocity); } if (oldClimbing != player.Character.climbing) { oldClimbing = player.Character.climbing; if (player.Character.climbing && climbingTime <= 0) { climbingTime = climbingDelay; animator.SetTrigger(climbParameter); } } if (!string.IsNullOrEmpty(crouchParameter)) { animator.SetBool(crouchParameter, player.Character.Crouching); } if (!string.IsNullOrEmpty(isGroundedParameter)) { animator.SetBool(isGroundedParameter, isGrounded); } //hands leftHandIK = new IKWeight(leftHandIK.position, leftHandIK.rotation, 0); rightHandIK = new IKWeight(rightHandIK.position, rightHandIK.rotation, 0); Transform chestTransform = animator.GetBoneTransform(HumanBodyBones.Chest); if (touching && !touching.gameObject.activeSelf) { touching = null; } if (player.GetCurrentWeapon().WeaponType == Weapon.WeaponTypes.Empty && touching && Vector3.Angle(transform.forward, (touching.position - transform.position).normalized) <= 90) { float leftHandDist = Vector3.Distance(transform.TransformPoint(startLeftHandPos), touching.position); float rightHandDist = Vector3.Distance(transform.TransformPoint(startRightHandPos), touching.position); Quaternion rot = Quaternion.LookRotation(transform.forward, (chestTransform.position - touching.position).normalized); if (Mathf.Min(leftHandDist, rightHandDist) <= 0.7f) { bool rightHand = rightHandDist < leftHandDist; leftHandIK = new IKWeight(touching.position, rot, rightHand ? 0 : 1); rightHandIK = new IKWeight(touching.position, rot, rightHand ? 1 : 0); } } if (player.Character.climbing) { leftHandIK = new IKWeight(player.Character.climbPoint - transform.right * 0.3f, transform.rotation, 1); rightHandIK = new IKWeight(player.Character.climbPoint + transform.right * 0.3f, transform.rotation, 1); } leftHandWeight = Mathf.Lerp(leftHandWeight, leftHandIK.weight, Time.deltaTime * 5); rightHandWeight = Mathf.Lerp(rightHandWeight, rightHandIK.weight, Time.deltaTime * 5); }