示例#1
0
    // calculate the target position and update the bones' rotation according to the position.
    void LateUpdate()
    {
        end.Follow(target.position);
        end.CalculateEndP();
        EasyIKBone next = end.parent;

        while (next != null)
        {
            next.Follow();
            next.CalculateEndP();
            next = next.parent;
        }
        if (start.transform.parent != null)
        {
            start.SetStartP(rootPosOffset + start.transform.parent.position);
        }
        else
        {
            start.SetStartP(start.transform.position);
        }

        start.CalculateEndP();
        start.UpdateRotation(weight);
        next = start.child;

        while (next != null)
        {
            next.AttachStartP();
            next.CalculateEndP();
            next.UpdateRotation(weight);
            next = next.child;
        }
    }
示例#2
0
    // initialize the esay ik bones
    void Start()
    {
        Transform  p       = transform.parent;
        EasyIKBone current = gameObject.GetComponent <EasyIKBone>();

        end   = current;
        start = current;
        for (int i = 1; i <= chainLength; i++)
        {
            EasyIKBone parent;
            if (chainLength == i)
            {
                if (p != null)
                {
                    parent = p.gameObject.GetComponent <EasyIKBone>();
                }
                else
                {
                    parent = null;
                }
            }
            else
            {
                if (p != null)
                {
                    parent = p.gameObject.GetComponent <EasyIKBone>();
                    if (parent == null)
                    {
                        parent = p.gameObject.AddComponent <EasyIKBone>();
                    }
                    start = parent;
                }
                else
                {
                    parent = null;
                }
            }
            current.Init(parent);
            if (p == null)
            {
                break;
            }
            p       = p.parent;
            current = parent;
        }
        if (start.transform.parent != null)
        {
            rootPosOffset = start.transform.position - start.transform.parent.position;
        }
        else
        {
            rootPosOffset = Vector3.zero;
        }
    }
示例#3
0
    public void Init(EasyIKBone parent_)
    {
        startP        = transform.position;
        localRotation = transform.localRotation;
        //managerRef = manager;
        parent = parent_;
        if (parent != null)
        {
            parent.child = this;
        }

        if (child != null)
        {
            endP       = child.transform.position;
            boneLength = Vector3.Distance(startP, endP);
        }
        else
        {
            endP       = startP;
            boneLength = 0f;
        }
    }