Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using DG.Tweening;
- using Sirenix.OdinInspector;
- using UnityEngine;
- public class HandsController : MonoBehaviour
- {
- [SerializeField]
- Transform leftHandIKTarget, rightHandIKTarget;
- Animator animator;
- Animator CurrentAnimator => transform.CachedComponent(ref animator);
- Vector3 currentLeft, currentRight;
- Quaternion currentQLeft, currentQRight;
- float speed = 10;
- bool reachIK;
- void Start()
- {
- reachIK = true;
- }
- void OnAnimatorIK(int _)
- {
- SetIk(AvatarIKGoal.LeftHand, leftHandIKTarget, ref currentLeft, ref currentQLeft, reachIK ? 1 : 0);
- SetIk(AvatarIKGoal.RightHand, rightHandIKTarget, ref currentRight, ref currentQRight, reachIK ? 1 : 0);
- }
- void SetIk(AvatarIKGoal iKGoal, Transform to, ref Vector3 current, ref Quaternion currentQ, float weight = 1)
- {
- current = Vector3.Slerp(current, to.position, Time.deltaTime * speed);
- CurrentAnimator.SetIKPositionWeight(iKGoal, weight);
- CurrentAnimator.SetIKPosition(iKGoal, current);
- currentQ = Quaternion.Slerp(currentQ, to.rotation, Time.deltaTime * speed);
- CurrentAnimator.SetIKRotationWeight(iKGoal, weight);
- CurrentAnimator.SetIKRotation(iKGoal, currentQ);
- }
- public void OnFinish()
- {
- reachIK = false;
- CurrentAnimator.SetBool("dance", true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment