Beispiel #1
0
        public bool Extend(float _speed)
        {
            if (!canResize)
            {
                return(false);
            }

            Link    rootLink       = links[links.Length - 1];
            Link    controlLink    = links[activeLinkCount - 1];
            Vector3 targetPosition = rootLink.transform.position - (controlLink.transform.up * linkSpacing * 2);

            if (activeLinkCount < (maxLinkCount - 1))
            {
                controlLink.ConnectedBody      = null;
                controlLink.transform.position = Vector3.MoveTowards(controlLink.transform.position, targetPosition, Mathf.Abs(_speed) * Time.deltaTime);

                if (Vector3.SqrMagnitude(controlLink.transform.position - rootLink.transform.position) > (linkSpacing * linkSpacing))
                {
                    Link addedLink = links[activeLinkCount];

                    addedLink.transform.position = controlLink.transform.position + ((rootLink.transform.position - controlLink.transform.position).normalized * linkSpacing);
                    addedLink.transform.rotation = controlLink.transform.rotation;

                    activeLinkCount++;

                    //addedLink.Joint.anchor = new Vector3(0, linkSpacing * (1f / linkScale), 0);
                    addedLink.IsActive = true;

                    controlLink.ConnectedBody = addedLink.Rigidbody;
                    controlLink = addedLink;
                }

                //controlLink.Joint.anchor = new Vector3(0, Vector3.Distance(rootLink.transform.position, controlLink.transform.position) * (1f / linkScale), 0);
                controlLink.ApplyJointSettings(Vector3.Distance(rootLink.transform.position, controlLink.transform.position) * (1f / linkScale));
                controlLink.ConnectedBody = rootLink.Rigidbody;
            }
            else
            {
                kVelocity = 0;
            }

            return(true);
        }
Beispiel #2
0
        public bool Retract(float _speed, int _minJointCount)
        {
            if (!canResize)
            {
                return(false);
            }

            Link rootLink    = links[links.Length - 1];
            Link controlLink = links[activeLinkCount - 1];

            controlLink.ConnectedBody      = null;
            controlLink.transform.position = Vector3.MoveTowards(controlLink.transform.position, rootLink.transform.position, Mathf.Abs(_speed) * Time.deltaTime);

            if (activeLinkCount > _minJointCount)
            {
                if (Vector3.SqrMagnitude(rootLink.transform.position - controlLink.transform.position) <= 0.01f)
                {
                    controlLink.IsActive = false;
                    activeLinkCount--;

                    controlLink = links[activeLinkCount - 1];

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
                    controlLink.RemoveJoint();
                    controlLink.ApplyJointSettings(Vector3.Distance(rootLink.transform.position, controlLink.transform.position) * (1f / linkScale));
#endif
                }
            }
            else
            {
                kVelocity = 0;
                controlLink.transform.position = rootLink.transform.position - (controlLink.transform.up * linkSpacing);
            }

            controlLink.Joint.anchor  = new Vector3(0, Vector3.Distance(rootLink.transform.position, controlLink.transform.position) * (1f / linkScale), 0);
            controlLink.ConnectedBody = rootLink.Rigidbody;

            return(true);
        }
Beispiel #3
0
        public bool Extend(float _speed)
        {
            if (!this.canResize)
            {
                return(false);
            }
            Link    link1     = this.links[this.links.Length - 1];
            Link    link2     = this.links[this.activeLinkCount - 1];
            Vector3 vector3_1 = Vector3.op_Subtraction(link1.transform.get_position(), Vector3.op_Multiply(Vector3.op_Multiply(link2.transform.get_up(), this.linkSpacing), 2f));

            if (this.activeLinkCount < this.maxLinkCount - 1)
            {
                link2.ConnectedBody = (Rigidbody)null;
                link2.transform.set_position(Vector3.MoveTowards(link2.transform.get_position(), vector3_1, Mathf.Abs(_speed) * Time.get_deltaTime()));
                if ((double)Vector3.SqrMagnitude(Vector3.op_Subtraction(link2.transform.get_position(), link1.transform.get_position())) > (double)this.linkSpacing * (double)this.linkSpacing)
                {
                    Link      link3     = this.links[this.activeLinkCount];
                    Transform transform = link3.transform;
                    Vector3   position  = link2.transform.get_position();
                    Vector3   vector3_2 = Vector3.op_Subtraction(link1.transform.get_position(), link2.transform.get_position());
                    Vector3   vector3_3 = Vector3.op_Multiply(((Vector3) ref vector3_2).get_normalized(), this.linkSpacing);
                    Vector3   vector3_4 = Vector3.op_Addition(position, vector3_3);
                    transform.set_position(vector3_4);
                    link3.transform.set_rotation(link2.transform.get_rotation());
                    ++this.activeLinkCount;
                    link3.IsActive      = true;
                    link2.ConnectedBody = link3.Rigidbody;
                    link2 = link3;
                }
                link2.ApplyJointSettings(Vector3.Distance(link1.transform.get_position(), link2.transform.get_position()) * (1f / this.linkScale));
                link2.ConnectedBody = link1.Rigidbody;
            }
            else
            {
                this.kVelocity = 0.0f;
            }
            return(true);
        }