public override void LateUpdate_IK(IMWeaponOwner RC) { if (RC.Aim && RC.WeaponAction != WA.Reload) { var UpVector = Vector3.up; Quaternion AimRotation = Quaternion.LookRotation(RC.AimDirection, UpVector); //Get the Rotation ... Vector3 ShoulderRotationAxis = RC.Aimer.AimTarget ? Vector3.Cross(UpVector, RC.AimDirection).normalized : RC.Aimer.MainCamera.transform.right; float angle = (Vector3.Angle(Vector3.up, RC.AimDirection) - 90); Debug.DrawRay(RC.Weapon.IsRightHanded ? RC.RightShoulder.position : RC.LeftShoulder.position, ShoulderRotationAxis * 0.33f, Color.yellow); if (RC.Weapon.IsRightHanded) //If the Weapon is RIGHT Handed { RC.RightShoulder.RotateAround(RC.RightShoulder.position, ShoulderRotationAxis, angle); //Rotate Up/Down the Right Shoulder to AIM Up/Down RC.RightShoulder.rotation *= Quaternion.Euler(RightShoulderOffset); if (!RC.Aimer.AimTarget) { RC.RightShoulder.RotateAround(RC.RightShoulder.position, Vector3.up, (RC.AimingSide ? 0 : -AimHorizontalOffset)); //Offset the RIGHT Arm for better view } } else //If the Weapon is LEFT Handed { RC.LeftShoulder.RotateAround(RC.LeftShoulder.position, ShoulderRotationAxis, angle); //Rotate Up/Down the Left Shoulder to AIM Up/Down RC.LeftShoulder.rotation *= Quaternion.Euler(LeftShoulderOffset); if (!RC.Aimer.AimTarget) { RC.LeftShoulder.RotateAround(RC.LeftShoulder.position, Vector3.up, (RC.AimingSide ? AimHorizontalOffset : 0)); //Offset the LEFT Arm for better view } } RC.Head.rotation = Quaternion.Slerp(RC.Head.rotation, AimRotation * Quaternion.Euler(HeadOffset), headLookWeight); //Head Look Rotation if (RC.WeaponAction != WA.Fire_Projectile) //Activate the Hand AIM DIRECTION when is not Firing or Reloading { if (RC.Weapon.IsRightHanded) { RC.RightHand.rotation = Delta_Rotation * Quaternion.Euler(RightHandOffset); } else { RC.LeftHand.rotation = Delta_Rotation * Quaternion.Euler(LeftHandOffset); } Delta_Rotation = Quaternion.Lerp(Delta_Rotation, AimRotation, Time.deltaTime * 20); //Smoothly AIM the Hand } } }
//protected virtual void FixAimPoseBow2(IMWeaponOwner RC) //{ // if (RC.Aim) // { // RC.Anim.SetLookAtWeight(1, 1, 1, 1, 0.1f); // RC.Anim.SetLookAtPosition(RC.Aimer.AimPoint); // } //} /// <summary>This will rotate the bones of the character to match the AIM direction </summary> protected virtual void FixAimPoseBow1(IMWeaponOwner RC) { var Bow = RC.Weapon as MShootable; if (RC.Aim) { RC.Anim.Update(0); var UpVector = Vector3.up; float Weight = Bow.IsRightHanded ? Bow.AimLimit.Evaluate(RC.HorizontalAngle) : Bow.AimLimit.Evaluate(-RC.HorizontalAngle); //The Weight evaluated on the AnimCurve Vector3 AimDirection = RC.AimDirection; Quaternion AimLookAt = Quaternion.LookRotation(AimDirection, UpVector); var angle = RC.Aimer.VerticalAngle * Weight; Vector3 ShoulderRotationAxis = Vector3.Cross(UpVector, AimDirection).normalized; Debug.DrawRay(RC.Chest.position, ShoulderRotationAxis, Color.yellow); RC.Chest.RotateAround(RC.Chest.position, ShoulderRotationAxis, angle / 2); //Nicely Done!! if (Bow.IsRightHanded) { RC.Chest.rotation *= Quaternion.Euler(ChestRight); RC.RightHand.rotation *= Quaternion.Euler(HandRight); RC.RightShoulder.rotation = Quaternion.Lerp(RC.RightShoulder.rotation, AimLookAt * Quaternion.Euler(ShoulderRight), Weight); // MakeDamage the boy always look to t } else { RC.Chest.rotation *= Quaternion.Euler(ChestLeft); RC.LeftHand.rotation *= Quaternion.Euler(HandLeft); RC.LeftShoulder.rotation = Quaternion.Lerp(RC.LeftShoulder.rotation, AimLookAt * Quaternion.Euler(ShoulderLeft), Weight); // MakeDamage the boy always look to t } } }
/// <summary> Stuff Set in the OnAnimatorIK </summary> public virtual void OnAnimator_IK(IMWeaponOwner RC) { }
/// <summary>Called on the Late Update of the Rider Combat Script </summary> public virtual void LateUpdate_IK(IMWeaponOwner RC) { }
//public override void OnAnimator_IK(IMWeaponOwner RC) //{ // FixAimPoseBow2(RC); // m_IKProfile?.ApplyOffsets(RC.Anim, RC.Aimer.AimDirection); //} public override void LateUpdate_IK(IMWeaponOwner RC) { FixAimPoseBow1(RC); }
public override void OnAnimator_IK(IMWeaponOwner RC) { float DeltaTime = RC.Anim.updateMode == AnimatorUpdateMode.AnimatePhysics ? Time.fixedDeltaTime : Time.deltaTime; bool isRightHand = RC.Weapon.IsRightHanded; Vector3 RayOrigin = isRightHand ? RC.RightShoulder.position : RC.LeftShoulder.position; Vector3 AimDirection = RC.AimDirection; Ray RayHand = new Ray(RayOrigin, AimDirection); Debug.DrawRay(RayHand.origin, RayHand.direction * 20, Color.clear); RC.WeaponIKW = Mathf.MoveTowards(RC.WeaponIKW, RC.Aim ? 1 : 0, DeltaTime * Smoothness); // RC.IKWeight = RC.Aim ? 1:0 ; var Action = Mathf.Abs(RC.WeaponAction); if (Action == WA.Reload) { RC.WeaponIKW = 0; } var HandIK = 1; if (Action == WA.Fire_Projectile) { HandIK = 0; } if (HandIK != 0) { float Hand_Distance = isRightHand ? HandIKDistance.Evaluate(RC.HorizontalAngle) : HandIKDistance.Evaluate(-RC.HorizontalAngle); //Values for the Distance of the Arm while rotating Hand_Distance *= HandDistance; //Vector3 LookDirection = RC.MainCamera.transform.forward; //Vector3 HandPosition = isRightHand ? RC.RightHand.position : RC.LeftHand.position; Vector3 HandOffset = isRightHand ? RightHandOffset : LeftHandOffset; Vector3 IKPoint = RayHand.GetPoint(Hand_Distance); //Vector3 LookDirectionFromHand = (RC.Aimer.AimHit.point - HandPosition).normalized; var HandRotation = Quaternion.LookRotation(AimDirection) * Quaternion.Euler(HandOffset); //Set the Aim Look Rotation for the Right or Left Hand var ikGoal = isRightHand ? AvatarIKGoal.RightHand : AvatarIKGoal.LeftHand; //Set the IK goal acording the Right or Left Hand //Arm IK RC.Anim.SetIKPosition(ikGoal, IKPoint); RC.Anim.SetIKPositionWeight(ikGoal, HandIK); RC.Anim.SetIKRotation(ikGoal, HandRotation); RC.Anim.SetIKRotationWeight(ikGoal, HandIK); } if (RC.WeaponIKW != 0 && RC.Aim) { //HeadIK RC.Anim.SetLookAtPosition(RayHand.GetPoint(10)); RC.Anim.SetLookAtWeight(1 * RC.WeaponIKW, 0.1f * RC.WeaponIKW, 1 * RC.WeaponIKW); } }