private void OnEnable()
    {
        //Get the two bone IK component running for the foor
        mTwoBoneIKConstraint = GetComponent <TwoBoneIKConstraint>();

        //initialize the position of the foot target as the tip of the two bone ik.
        transform.position = tip.position;
    }
Esempio n. 2
0
    void Awake()
    {
        ikConstraint = transform.GetComponent <TwoBoneIKConstraint>();

        target          = new GameObject(transform.name + "_Target").transform;
        target.position = transform.position;

        hint          = new GameObject(transform.name + "_Pole").transform;
        hint.position = transform.position;

        ikConstraint.data.target = target;
        ikConstraint.data.hint   = hint;
    }
Esempio n. 3
0
    public virtual IEnumerator LerpFloat(TwoBoneIKConstraint twoBone, float lerpTo)
    {
        float timeElapsed   = 0;
        float moveDuration  = 0.5f;
        float currentWeight = twoBone.weight;

        while (timeElapsed < moveDuration)
        {
            timeElapsed += Time.deltaTime;
            float normalizedTime = timeElapsed / moveDuration;

            twoBone.weight = Mathf.Lerp(twoBone.weight, lerpTo, normalizedTime);

            yield return(null);
        }
    }
Esempio n. 4
0
    public void CreateRig()
    {
        if (rigBuilder == null)
        {
            rigBuilder = transform.parent.gameObject.AddComponent <RigBuilder>();
        }

        if (rigGameObject == null)
        {
            rigGameObject = new GameObject("rig");
            rigGameObject.transform.SetParent(rigBuilder.transform);
        }

        if (rig == null)
        {
            rig = rigGameObject.AddComponent <Rig>();
            rigBuilder.layers.Add(new RigLayer(rig));
        }

        if (twoBoneManager == null)
        {
            twoBoneManager = new GameObject("ik");
            twoBoneManager.transform.SetParent(rigGameObject.transform);
        }

        twoBoneManager.transform.position = lowLegPosition.position;

        if (twoBoneIK == null)
        {
            twoBoneIK             = twoBoneManager.AddComponent <TwoBoneIKConstraint>();
            twoBoneIK.data.root   = upLegPivot.transform;
            twoBoneIK.data.mid    = midLegPivot.transform;
            twoBoneIK.data.tip    = lowLegPivot.transform;
            twoBoneIK.data.target = twoBoneManager.transform;
        }

        if (hint == null)
        {
            hint = new GameObject("hint");
            hint.transform.SetParent(twoBoneManager.transform);
            twoBoneIK.data.hint = hint.transform;
        }

        hint.transform.position = midLegPosition.position + new Vector3(0, 0, 1);
    }
Esempio n. 5
0
 private void ToggleLedgeGrabArm(Vector3 ledgePoint, Vector3 ledgeNormal)
 {
     foreach (Transform bone in controlBones)
     {
         if (bone.name == "Arm_IK_R")
         {
             TwoBoneIKConstraint twoBone = bone.GetComponent <TwoBoneIKConstraint>();
             if (ledgePoint != Vector3.zero)
             {
                 twoBone.transform.position += ledgePoint;
                 twoBone.weight              = 1f;
                 twoBone.transform.rotation  = Quaternion.LookRotation(new Vector3(-ledgeNormal.x, 0, -ledgeNormal.z));
             }
             else
             {
                 twoBone.weight = 0f;
             }
         }
     }
 }
Esempio n. 6
0
 private void ToggleAimBuster(Transform other)
 {
     foreach (Transform bone in controlBones)
     {
         if (bone.name == "Arm_IK_L")
         {
             IK_Follow           ik_follow = bone.GetComponent <IK_Follow>();
             TwoBoneIKConstraint twobone   = bone.GetComponent <TwoBoneIKConstraint>();
             if (other != null)
             {
                 ik_follow.target = other;
                 StartCoroutine(LerpFloat(twobone, 1f));
             }
             else
             {
                 ik_follow.target = null;
                 StartCoroutine(LerpFloat(twobone, 0f));
             }
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="baseConstraint">Base constraint to override.</param>
 public TwoBoneIKInverseConstraint(TwoBoneIKConstraint baseConstraint) : base(baseConstraint)
 {
 }
    public static void TwoBoneIKAutoSetupUtility(TwoBoneIKConstraint constraint)
    {
        var tip = constraint.data.tip;

        if (!constraint.data.mid)
        {
            Undo.RecordObject(constraint, "Setup mid bone for TwoBoneIK");
            constraint.data.mid = tip.parent;
            if (PrefabUtility.IsPartOfPrefabInstance(constraint))
            {
                EditorUtility.SetDirty(constraint);
            }
        }

        if (!constraint.data.root)
        {
            Undo.RecordObject(constraint, "Setup root bone for TwoBoneIK");
            constraint.data.root = tip.parent.parent;
            if (PrefabUtility.IsPartOfPrefabInstance(constraint))
            {
                EditorUtility.SetDirty(constraint);
            }
        }

        if (!constraint.data.target)
        {
            var target = constraint.transform.Find(constraint.gameObject.name + "_target");
            if (target == null)
            {
                var t = new GameObject();
                Undo.RegisterCreatedObjectUndo(t, "Created target");
                t.name = constraint.gameObject.name + "_target";
                Undo.SetTransformParent(t.transform, constraint.transform, "Set new parent");
                target = t.transform;
                if (PrefabUtility.IsPartOfPrefabInstance(constraint))
                {
                    EditorUtility.SetDirty(constraint);
                }
            }
            constraint.data.target = target;
        }

        if (!constraint.data.hint)
        {
            var hint = constraint.transform.Find(constraint.gameObject.name + "_hint");
            if (hint == null)
            {
                var t = new GameObject();
                Undo.RegisterCreatedObjectUndo(t, "Created hint");
                t.name = constraint.gameObject.name + "_hint";
                Undo.SetTransformParent(t.transform, constraint.transform, "Set new parent");
                hint = t.transform;
            }
            constraint.data.hint = hint;
            if (PrefabUtility.IsPartOfPrefabInstance(constraint))
            {
                EditorUtility.SetDirty(constraint);
            }
        }

        // align target and hint to bones
        constraint.data.target.position = constraint.data.tip.position;
        constraint.data.target.rotation = constraint.data.tip.rotation;

        constraint.data.hint.position = constraint.data.mid.position;
        constraint.data.hint.rotation = constraint.data.mid.rotation;
    }
Esempio n. 9
0
 // Start is called before the first frame update
 void Start()
 {
     iK = GetComponent <TwoBoneIKConstraint>();
 }