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.
 
 
 
 

54 lines
1.3 KiB

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<FixedJoint>();
}
// 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<FixedJoint>());
}
}
}