using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Animations.Rigging; namespace Moloch { public class IKManager : MonoBehaviour { // Avatar private GameObject m_Target; public Rig m_Rig; public GameObject m_RightHandSource; public GameObject m_LeftHandSource; public Rigidbody m_Hip; private FixedJoint m_TargetFixedJoint; // Set target and fixed joint public void SetTarget(GameObject target) { m_Target = target; m_TargetFixedJoint = target.GetComponentInChildren(); } // Set IK of hands to position of target (hands) public void SetIKTransform() { m_RightHandSource.transform.position = m_Target.transform.position; m_LeftHandSource.transform.position = m_Target.transform.position; } public void SetWeight(float weight) { m_Rig.weight = weight; } public void ConnectJoint() { SetIKTransform(); SetWeight(1f); m_TargetFixedJoint.connectedBody = m_Hip; } public void ReleaseJoint() { SetWeight(0f); Destroy(m_Target.GetComponent()); } } }