Global Game Jam 2023
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

1 year ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NaughtyAttributes;
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public class IkController : MonoBehaviour
  9. {
  10. #region Inspector Fields
  11. [SerializeField, BoxGroup("References")]
  12. private HandController m_leftHandTarget, m_rightHandTarget;
  13. [SerializeField, BoxGroup("References")]
  14. private Animator m_animator;
  15. [SerializeField, BoxGroup("Settings"),Range(0,1)]
  16. public float IKWeight = 1;
  17. #endregion Inspector Fields
  18. #region Private Fields
  19. #endregion Private Fields
  20. #region Getters
  21. #endregion Getters
  22. #region MonoBehaviour Functions
  23. /// <summary>
  24. /// OnEnable is called when the object becomes enabled and active.
  25. /// </summary>
  26. private void OnEnable()
  27. {
  28. }
  29. /// <summary>
  30. /// OnDisable is called when the behaviour becomes disabled.
  31. /// </summary>
  32. private void OnDisable()
  33. {
  34. }
  35. /// <summary>
  36. /// Update is called once per frame
  37. /// </summary>
  38. private void Update()
  39. {
  40. }
  41. //a callback for calculating IK
  42. void OnAnimatorIK()
  43. {
  44. if (m_animator)
  45. {
  46. m_animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
  47. m_animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
  48. m_animator.SetIKPosition(AvatarIKGoal.LeftHand, m_leftHandTarget.GetIKPosition());
  49. m_animator.SetIKRotation(AvatarIKGoal.LeftHand, m_leftHandTarget.GetIKRotation());
  50. m_animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
  51. m_animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
  52. m_animator.SetIKPosition(AvatarIKGoal.RightHand, m_rightHandTarget.GetIKPosition());
  53. m_animator.SetIKRotation(AvatarIKGoal.RightHand, m_rightHandTarget.GetIKRotation());
  54. }
  55. }
  56. #endregion MonoBehaviour Functions
  57. #region Class Functionality
  58. #endregion Class Functionality
  59. #region Editor Functions
  60. /// <summary>
  61. /// Called when the Component is created or Reset from the Inspector
  62. /// </summary>
  63. private void Reset()
  64. {
  65. //useful for finding components on creation
  66. }
  67. #endregion Editor Functions
  68. }