Example #1
0
    public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, Vector3 hingeAxis, bool centerOnIndex)
    {
        if (gameObject.GetComponent <QuickRope2Cloth>())
        {
            Debug.LogError("You must use the \"Cloth\" component to attach objects when using the Cloth mesh type.");
            return;
        }

        RopeAttachedObject rao = new RopeAttachedObject();

        rao.go         = obj;
        rao.jointIndex = jointIndex;
        rao.jointType  = jointType;
        rao.hingeAxis  = hingeAxis;

        if (centerOnIndex)
        {
            rao.go.transform.position = Joints[rao.jointIndex].transform.position;
        }

        attachedObjects.Add(rao);

        if (Application.isPlaying)
        {
            if (rao.go == null)
            {
                return;
            }

            switch (rao.jointType)
            {
            case RopeAttachmentJointType.Fixed:
                rao.jointRef = Joints[rao.jointIndex].AddComponent <FixedJoint>();
                rao.jointRef.connectedBody = rao.go.rigidbody;
                break;

            case RopeAttachmentJointType.Hinge:
                //rao.jointRef = Joints[rao.jointIndex].AddComponent<HingeJoint>();
                //(rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                //rao.jointRef.connectedBody = rao.go.rigidbody;

                rao.jointRef = rao.go.AddComponent <HingeJoint>();                    //ao.jointRef = Joints[ao.jointIndex].AddComponent<HingeJoint>();
                (rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                rao.jointRef.connectedBody        = Joints[rao.jointIndex].rigidbody; //ao.jointRef.connectedBody = ao.go.rigidbody;

                break;
            }
        }
    }
Example #2
0
    public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, Vector3 hingeAxis, bool centerOnIndex)
    {
        if (gameObject.GetComponent<QuickRope2Cloth>())
        {
            Debug.LogError("You must use the \"Cloth\" component to attach objects when using the Cloth mesh type.");
            return;
        }

        RopeAttachedObject rao = new RopeAttachedObject();
        rao.go = obj;
        rao.jointIndex = jointIndex;
        rao.jointType = jointType;
        rao.hingeAxis = hingeAxis;

        if (centerOnIndex)
            rao.go.transform.position = Joints[rao.jointIndex].transform.position;

        attachedObjects.Add(rao);

        if (Application.isPlaying)
        {
            if (rao.go == null)
                return;

            switch (rao.jointType)
            {
                case RopeAttachmentJointType.Fixed:
                    rao.jointRef = Joints[rao.jointIndex].AddComponent<FixedJoint>();
                    rao.jointRef.connectedBody = rao.go.rigidbody;
                    break;
                case RopeAttachmentJointType.Hinge:
                    //rao.jointRef = Joints[rao.jointIndex].AddComponent<HingeJoint>();
                    //(rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                    //rao.jointRef.connectedBody = rao.go.rigidbody;

                    rao.jointRef = rao.go.AddComponent<HingeJoint>();//ao.jointRef = Joints[ao.jointIndex].AddComponent<HingeJoint>();
                    (rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                    rao.jointRef.connectedBody = Joints[rao.jointIndex].rigidbody;//ao.jointRef.connectedBody = ao.go.rigidbody;

                    break;
            }
        }
    }
Example #3
0
    void AttachObjects()
    {
        if (enablePhysics && Application.isPlaying)
        {
            foreach (RopeAttachedObject ao in attachedObjects)
            {
                if (ao.go == null)
                    continue;

                if (ao.jointIndex > Joints.Count - 1)
                    ao.jointIndex = Joints.Count - 1;

                switch (ao.jointType)
                {
                    case RopeAttachmentJointType.Fixed:
                        ao.jointRef = Joints[ao.jointIndex].AddComponent<FixedJoint>();
                        ao.jointRef.connectedBody = ao.go.rigidbody;

                        if (ao.go.CompareTag("Hook"))
                        {
                            hook = ao.go;
                            hookO = ao;
                        }

                        break;
                    case RopeAttachmentJointType.Hinge:
                        ao.jointRef = ao.go.AddComponent<HingeJoint>();//ao.jointRef = Joints[ao.jointIndex].AddComponent<HingeJoint>();
                        (ao.jointRef as HingeJoint).axis = ao.hingeAxis;
                        ao.jointRef.connectedBody = Joints[ao.jointIndex].rigidbody;//ao.jointRef.connectedBody = ao.go.rigidbody;
                        break;
                }
            }
        }
    }