IKPuppetTarget.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Samples.InverseKinematics
  5. {
  6. /// <summary>An object for one of a character's limbs to aim at using Inverse Kinematics (IK).</summary>
  7. ///
  8. /// <remarks>
  9. /// <strong>Sample:</strong>
  10. /// <see href="https://kybernetik.com.au/animancer/docs/samples/ik/puppet">
  11. /// Puppet</see>
  12. /// </remarks>
  13. ///
  14. /// https://kybernetik.com.au/animancer/api/Animancer.Samples.InverseKinematics/IKPuppetTarget
  15. ///
  16. [AddComponentMenu(Strings.SamplesMenuPrefix + "Inverse Kinematics - IK Puppet Target")]
  17. [AnimancerHelpUrl(typeof(IKPuppetTarget))]
  18. public class IKPuppetTarget : MonoBehaviour
  19. {
  20. /************************************************************************************************************************/
  21. [SerializeField] private AvatarIKGoal _Type;
  22. [SerializeField, Range(0, 1)] private float _PositionWeight = 1;
  23. [SerializeField, Range(0, 1)] private float _RotationWeight = 0;
  24. /************************************************************************************************************************/
  25. public void UpdateAnimatorIK(Animator animator)
  26. {
  27. animator.SetIKPositionWeight(_Type, _PositionWeight);
  28. animator.SetIKRotationWeight(_Type, _RotationWeight);
  29. animator.SetIKPosition(_Type, transform.position);
  30. animator.SetIKRotation(_Type, transform.rotation);
  31. }
  32. /************************************************************************************************************************/
  33. }
  34. }