Ejemplo n.º 1
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.transform.CompareTag("Attachable") && !snake.isAppleBitten)
        {
            var activeHead = gameObject.GetComponentInChildren <SnakeHead>();

            FixedJoint[] joints = activeHead.GetComponentsInChildren <FixedJoint>();
            joint = joints[1];
            joint.connectedBody = collision.transform.GetComponent <Rigidbody>();

            targetRb             = collision.gameObject.GetComponent <Rigidbody>();
            targetRb.isKinematic = false;

            snake.isAppleBitten = true;

            soundController.PlayBiteSound();
        }
    }
Ejemplo n.º 2
0
    void OnNailTipTrigger(object other)
    {
        Collider otherCollider = (Collider)other;

        if (otherCollider != null && !_currentConnectedColliders.Contains(otherCollider))
        {
            Rigidbody otherRigidBody = otherCollider.GetComponent <Rigidbody>();
            if (otherRigidBody)
            {
                FixedJoint fixJoint = AddFixedJoint(gameObject);
                fixJoint.connectedBody = otherRigidBody;

                _currentConnectedColliders.Add(otherCollider);

                _nailBodyCollider.enabled = false;
            }
        }
    }
Ejemplo n.º 3
0
    void StartGame()
    {
        if (rb == null)
        {
            Destroy(gameObject);
        }
        rb.isKinematic = false;

        for (int i = 0; i < joints.Count; i++)
        {
            if (joints[i].connectedBody == null)
            {
                FixedJoint f = joints[i];
                joints.Remove(joints[i]);
                Destroy(f);
            }
        }
    }
Ejemplo n.º 4
0
    void OnTriggerStay(Collider col)
    {
        Debug.Log("You collided with " + col.name + " and activated OnTriggerStay.");

        if ((fixedJoint == null) && (dev.GetTouch(SteamVR_Controller.ButtonMask.Trigger)))
        {
            fixedJoint = col.gameObject.AddComponent <FixedJoint>();
            fixedJoint.connectedBody = rigidBodyAttachPoint;
        }
        else if (fixedJoint != null && dev.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
        {
            GameObject go = fixedJoint.gameObject;
            Rigidbody  rb = go.GetComponent <Rigidbody>();
            Object.Destroy(fixedJoint);
            fixedJoint = null;
            tossObject(rb);
        }
    }
Ejemplo n.º 5
0
    public void Drop(FixedJoint targetJoint)
    {
        if (!currentInteractable)
        {
            return;
        }

        Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>();

        targetBody.velocity        = pose.GetVelocity();
        targetBody.angularVelocity = pose.GetAngularVelocity();

        fixedJoint.connectedBody       = null;
        currentInteractable.activeHand = null;
        currentInteractable            = null;

        targetJoint.connectedBody = targetBody;
    }
Ejemplo n.º 6
0
Archivo: Seat.cs Proyecto: samhogan/AUG
    void Update()
    {
        if (Vector3.Distance(player.position, transform.position) < 2 && Input.GetKey("j"))
        {
            player.gameObject.transform.position = transform.position + transform.up * 1.1f;

            FixedJoint joint = gameObject.AddComponent <FixedJoint>();
            joint.connectedBody = player;

            /*HingeJoint joint = gameObject.AddComponent<HingeJoint>();
             *
             * joint.axis = transform.up;
             * joint.connectedBody = player;*/
            PlayerMove1.sitting = true;

            player.constraints = RigidbodyConstraints.None;
        }
    }
Ejemplo n.º 7
0
    private FixedJoint AddFixedJoint(GameObject connectedObject, int connections)
    {
        FixedJoint fx = gameObject.AddComponent <FixedJoint>();

        fx.breakForce  = 2000;
        fx.breakTorque = 2000;

        //----- her ------
        // is this needed?
        //connectedObject.transform.position = transform.position;


        fx.autoConfigureConnectedAnchor = true;
        fx.enableCollision = false;
        fx.connectedBody   = connectedObject.GetComponent <Rigidbody>();

        return(fx);
    }
Ejemplo n.º 8
0
 void OnCollisionEnter(Collision collision)
 {
     foreach (ContactPoint contact in collision.contacts)
     {
         Debug.DrawRay(contact.point, contact.normal, Color.white);
     }
     if (collision.gameObject.name == "Cube")
     {
         SpringJoint spring = GetComponent <SpringJoint>();
         if (spring != null)
         {
             Destroy(spring);
         }
         FixedJoint head_joint = gameObject.AddComponent <FixedJoint>();
         head_joint.breakForce  = breakForce;
         head_joint.breakTorque = breakTorque;
     }
 }
Ejemplo n.º 9
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.name == "Concave" &&
         HoloToolkit.Unity.InputModule.HandDraggable._isDragging == false &&
         fj == null)
     {
         Debug.Log("Hit"); // ログを表示する
                           //rigid.velocity = Vector3.zero;
                           //rigid.angularVelocity = Vector3.zero;
         other.transform.root.transform.rotation = this.transform.rotation;
         other.transform.root.transform.position = this.transform.GetChild(0).position + new Vector3(0, 0.012f, 0);
         gameObject.AddComponent <FixedJoint>();
         fj               = gameObject.GetComponent <FixedJoint>();
         fj.breakForce    = 100;
         fj.breakTorque   = 100;
         fj.connectedBody = other.transform.root.GetComponent <Rigidbody>();
     }
 }
Ejemplo n.º 10
0
    void Grab()
    {
        if (m_touchingObject.GetComponent <Rigidbody>().mass > 10)
        {
            return;
        }

        m_heldObject = m_touchingObject;
        m_heldObject.GetComponent <Rigidbody>().isKinematic = true;
        m_heldObject.transform.SetParent(transform);

        FixedJoint fx = gameObject.AddComponent <FixedJoint>();

        fx.connectedBody = m_heldObject.GetComponent <Rigidbody>();
        fx.axis          = transform.forward;
        fx.breakForce    = 5000;
        fx.breakTorque   = 5000;
    }
Ejemplo n.º 11
0
 void OnCollisionStay(Collision collision)
 {
     if (collision.collider.attachedRigidbody != null && Input.GetKey(KeyCode.LeftShift) && collision.collider.attachedRigidbody.tag == "grabbable")
     {
         body2 = collision.collider.attachedRigidbody;
         flag  = 1;
         if (fj == null)
         {
             gameObject.AddComponent <FixedJoint>();
             fj = GetComponent <FixedJoint>();
             fj.connectedBody = body2;
         }
     }
     else if (fj != null && !Input.GetKey(KeyCode.LeftShift))
     {
         Component.Destroy(fj);
     }
 }
Ejemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        if (!grabbing && grabbableObject != null && ((side == PC_Grab.HandSide.right && OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > 0) || (side == PC_Grab.HandSide.left && OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > 0)))
        {
            grabbing = true;
            FixedJoint joint = grabbableObject.AddComponent <FixedJoint>();
            joint.connectedBody = rbody;
        }

        if (grabbing && ((side == PC_Grab.HandSide.right && OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) == 0) || (side == PC_Grab.HandSide.left && OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) == 0)))
        {
            grabbing = false;
            FixedJoint joint = grabbableObject.GetComponentInParent <FixedJoint>();
            Destroy(joint);
            grabbableObject.GetComponent <Rigidbody>().velocity = OVRInput.GetLocalControllerVelocity((side == PC_Grab.HandSide.left) ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch);
            //grabbableObject = null;
        }
    }
Ejemplo n.º 13
0
        IEnumerator WaitAndStaticAttach()
        {
            // Wait for part to become active in case of it came from inventory.
            while (!part.started && part.State != PartStates.DEAD)
            {
                yield return(new WaitForFixedUpdate());
            }
            part.vessel.Landed = true;

            DebugEx.Fine("Create fixed joint attached to the world");
            if (staticAttachJoint)
            {
                Destroy(staticAttachJoint);
            }
            staticAttachJoint             = part.gameObject.AddComponent <FixedJoint>();
            staticAttachJoint.breakForce  = staticAttachBreakForce;
            staticAttachJoint.breakTorque = staticAttachBreakForce;
        }
Ejemplo n.º 14
0
 public void Equip(Transform parent, Vector3 position, Quaternion rotation, bool usePhysics)
 {
     transform.position = position;
     transform.rotation = rotation;
     if (usePhysics)
     {
         hookGunRb.isKinematic = false;
         Rigidbody parentRb = parent.GetComponent <Rigidbody>();
         attachJoint = gameObject.AddComponent <FixedJoint>();
         attachJoint.connectedBody = parentRb;
         attachJoint.breakForce    = float.PositiveInfinity;
     }
     else
     {
         hookGunRb.isKinematic = true;
     }
     transform.parent = parent;
 }
Ejemplo n.º 15
0
    void DetachFromHand()
    {
        Debug.Log("detached from hand");
        Object.DestroyImmediate(joint);
        joint = null;
        if (rb)
        {
            //rb.isKinematic = false;
            rb.useGravity    = true;
            rb.interpolation = RigidbodyInterpolation.Interpolate;
        }
        var collider = GetComponent <Collider>();

        if (collider)
        {
            collider.enabled = true;
        }
    }
Ejemplo n.º 16
0
        public void Initialize(Vector3 position, Vector3 scale, GameObject triggerObject)
        {
            gameObject.transform.parent           = GameObject.Find("SATSUMA(557kg, 248)").transform;
            gameObject.transform.localPosition    = position;
            gameObject.transform.localEulerAngles = Vector3.zero;
            gameObject.transform.localScale       = scale;

            BoxCollider collider = gameObject.AddComponent <BoxCollider>();

            collider.isTrigger = true;

            rb             = gameObject.AddComponent <Rigidbody>();
            rb.isKinematic = false;
            rb.useGravity  = true;
            rb.mass        = .1f;

            trunkContent = new List <GameObject>();

            storageOpen = triggerObject.GetComponent <PlayMakerFSM>().FsmVariables.GetFsmBool("Open");

            bool disableAfterHook = false;

            if (!triggerObject.activeSelf)
            {
                disableAfterHook = true;
                triggerObject.SetActive(true);
            }

            FsmHook.FsmInject(triggerObject, "Mouse off", OnBootAction);

            if (disableAfterHook)
            {
                triggerObject.SetActive(false);
            }

            rearSeatPivot = GameObject.Find("SATSUMA(557kg, 248)").transform.Find("Interior/pivot_seat_rear");

            FixedJoint joint = gameObject.AddComponent <FixedJoint>();

            joint.connectedBody       = transform.parent.root.gameObject.GetComponent <Rigidbody>();
            joint.breakForce          = Mathf.Infinity;
            joint.breakTorque         = Mathf.Infinity;
            joint.enablePreprocessing = true;
        }
Ejemplo n.º 17
0
 public int Execute (GameObject target)
 /*
     Call this continuously to execute the routine
     Return codes:
     0: Routine complete
     2: Routine in progress
 */
 {
     //Debug.Log(string.Format("Pickup at state {0}", state));
     targetRb = target.GetComponent<Rigidbody> ();
     targetTr = target.GetComponent<Transform> ();
     switch(state)
     {
     // Move near the object to be picked up
     case 0:
         armControls.SetStaticPosition("idle");
         if (movementControls.DriveTo(target.transform, true) == 0)
         {
             state = 1;
             leftWheel.constraints = rightWheel.constraints = RigidbodyConstraints.FreezeRotation;
         }
         return 2;
     case 1:
         targetRb.velocity = Vector3.zero;
         if (armControls.SetStaticPosition("sides") == 0)
         {
             state = 2;
         }
         return 2;
     case 2:
         if (armControls.SetStaticPosition("forwardL") == 0)
         {
             posDiff = leftHand.position - targetTr.position;
             leftAttachJoint = leftHand.gameObject.AddComponent<FixedJoint> ();
             rightAttachJoint = rightHand.gameObject.AddComponent<FixedJoint> ();
             leftAttachJoint.connectedBody = targetRb;
             rightAttachJoint.connectedBody = targetRb;
             leftWheel.constraints = rightWheel.constraints = RigidbodyConstraints.None;
             state = 3; // Move on to holding state, keep holding object in FixedUpdate
         }
         return 2;
     }
     return 0;
 }
        /// <summary>
        /// Loads and instantiates a socket avatar prefab from Resources/Avatars/Sockets.
        /// The prefab must include the tag "Socket". Loads by name.
        /// </summary>
        /// <param name="socketType">The name of the prefab socket avatar to be loaded.</param>
        /// <returns>The instantiated socket GameObject.</returns>
        private static GameObject LoadSocket(string socketType)
        {
            // Need to attach to ResidualLimbAvatar, so find that first and get its Rigidbody.
            GameObject residualLimbGO = GameObject.FindGameObjectWithTag("ResidualLimbAvatar");
            Rigidbody  residualLimbRB = residualLimbGO.GetComponent <Rigidbody>();

            // Load socket from avatar folder and check whether successfully loaded.
            GameObject socketPrefab = Resources.Load <GameObject>("Avatars/Sockets/" + socketType);

            if (socketPrefab == null)
            {
                throw new System.Exception("The requested socket prefab was not found.");
            }

            // Get parent prosthesis manager
            GameObject prosthesisManagerGO = GameObject.FindGameObjectWithTag("ProsthesisManager");

            // Load socket object info
            //string objectPath = resourcesDataPath + "/Sockets/" + socketType + ".json";
            //string objectDataAsJson = File.ReadAllText(objectPath);
            string objectPath       = "Avatars/Sockets/" + socketType;
            string objectDataAsJson = Resources.Load <TextAsset>(objectPath).text;

            activeSocketData = JsonUtility.FromJson <AvatarObjectData>(objectDataAsJson);
            if (activeSocketData == null)
            {
                throw new System.Exception("The requested socket information was not found.");
            }

            // Instantiate with prosthesis manager as parent.
            GameObject socketGO = Object.Instantiate(socketPrefab, new Vector3(socketPrefab.transform.localPosition.x, -(activeResidualLimbData.dimensions.x + (activeSocketData.dimensions.x / 2.0f)), socketPrefab.transform.localPosition.z), socketPrefab.transform.localRotation, prosthesisManagerGO.transform);

            // Attach the socket to the residual limb through a fixed joint.
            FixedJoint socketFixedJoint = socketGO.GetComponent <FixedJoint>();

            // If no fixed joint was found, then add it.
            if (socketFixedJoint == null)
            {
                socketFixedJoint = socketGO.AddComponent <FixedJoint>();
            }
            // Connect
            socketFixedJoint.connectedBody = residualLimbRB;
            return(socketGO);
        }
Ejemplo n.º 19
0
    public void OnTriggerDown(Transform controller, int controllerIndex)
    {
        GameObject attachPoint = controller.GetComponent <TouchController>().attachPoint;

        Rigidbody controllerRigidbody = attachPoint.GetComponent <Rigidbody>();

        if (!controllerRigidbody)
        {
            controllerRigidbody             = attachPoint.AddComponent <Rigidbody>();
            controllerRigidbody.isKinematic = true;
            controllerRigidbody.useGravity  = true;
        }

        fixedJoint               = gameObject.AddComponent <FixedJoint>();
        fixedJoint.anchor        = transform.InverseTransformPoint(attachPoint.transform.position);
        fixedJoint.connectedBody = controllerRigidbody;
        fixedJoint.breakForce    = Mathf.Infinity;
        fixedJoint.breakTorque   = Mathf.Infinity;
    }
Ejemplo n.º 20
0
 void GrabObject()
 {
     if (objToGrab != null)
     {
         grabbedObj = objToGrab;
         grabbedObj.transform.parent = this.transform;
         grabbedObjRb              = grabbedObj.GetComponent <Rigidbody> ();
         joint                     = gameObject.AddComponent <FixedJoint> ();
         joint.connectedBody       = grabbedObjRb;
         joint.enablePreprocessing = false;
         grabbedObjRb.useGravity   = false;
         DebrisManager piece;
         if (piece = grabbedObj.GetComponent <DebrisManager> ())
         {
             piece.beingHeld       = true;
             piece.collateralLevel = 1;
         }
     }
 }
Ejemplo n.º 21
0
    void OnGrab(GameObject controller)
    {
        Debug.Log("ON GRAB : " + controller.name);
        Debug.Log("ATTACH CONTROLLER TO VALVE");
        FixedJoint fx = gameObject.AddComponent <FixedJoint>();

        fx.breakForce    = 20000;
        fx.breakTorque   = 20000;
        fx.connectedBody = controller.GetComponent <Rigidbody>();

        numberOfControllersGrabbed = gameObject.GetComponents <FixedJoint>().Count();

        Debug.Log(numberOfControllersGrabbed);
        if (numberOfControllersGrabbed == 2)
        {
            Debug.Log("TWO CONTROLLERS ARE ON THE VALVE");
            this.gameObject.GetComponent <Rigidbody>().isKinematic = false;
        }
    }
Ejemplo n.º 22
0
	void connectToNeighbours(triangleNode n)
	{
		Vector2[] possibleoffsets = {new Vector2(-1,0), new Vector2(1,0), new Vector2(0,1)};

		if(isPointingUp(n))
		{
			possibleoffsets[2] = new Vector2(0, -1);
		}
		
		for(int i=0; i < possibleoffsets.Length; i++)
		{
			if(getNode((int)(n.x + possibleoffsets[i].x), (int)(n.y + possibleoffsets[i].y)) != null)
			{
				triangleNode t = getNode((int)(n.x + possibleoffsets[i].x), (int)(n.y + possibleoffsets[i].y));
				FixedJoint f = n.triangleObject.AddComponent<FixedJoint>();
				f.connectedBody = t.triangleObject.GetComponent<Rigidbody>();
			}
		}
	}
Ejemplo n.º 23
0
 public void Grab(GameObject aToFollow)
 {
     if (mLocked)
     {
         return;
     }
     if (!mIsFollowing)
     {
         // add a fixed joint to follow the object
         mJoint = gameObject.AddComponent <FixedJoint>();
         mJoint.connectedBody = aToFollow.GetComponent <Rigidbody>();
         mJoint.breakForce    = 100000.0f;
         // set the tracking to true
         mIsFollowing = true;
         mToFollow    = aToFollow;
         // set the highlight to the defined grabbing color
         mHighlighter.ConstantOn(mGrabColor);
     }
 }
Ejemplo n.º 24
0
    private void GrabEnd()
    {
        holdJoint?.Remove();
        holdJoint = null;

        if (HeldBody.IsValid())
        {
            HeldBody.AutoSleep = true;
        }

        if (HeldEntity.IsValid())
        {
            Client?.Pvs.Remove(HeldEntity);
        }

        HeldBody   = null;
        HeldRot    = Rotation.Identity;
        HeldEntity = null;
    }
Ejemplo n.º 25
0
        public override void OnGrabStart(Transform controller, int controllerIndex)
        {
            Rigidbody controllerRigidbody = controller.gameObject.GetComponent <Rigidbody>();

            if (!controllerRigidbody)
            {
                controllerRigidbody             = controller.gameObject.AddComponent <Rigidbody>();
                controllerRigidbody.isKinematic = true;
                controllerRigidbody.useGravity  = true;
            }
            dragStartPosition         = controller.position;
            fixedJoint                = gameObject.AddComponent <FixedJoint>();
            fixedJoint.anchor         = transform.InverseTransformPoint(controller.position);
            fixedJoint.connectedBody  = controllerRigidbody;
            fixedJoint.breakForce     = Mathf.Infinity;
            fixedJoint.breakTorque    = Mathf.Infinity;
            rigidbody.velocity        = Vector3.zero;
            rigidbody.angularVelocity = Vector3.zero;
        }
Ejemplo n.º 26
0
    void FixedUpdate()
    {
        var device = SteamVR_Controller.Input((int)trackedObj.index);

        if (joint == null && device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            var go = GameObject.Instantiate(prefab);
            go.transform.position = attachPoint.transform.position;

            joint = go.AddComponent <FixedJoint>();
            joint.connectedBody = attachPoint;
        }
        else if (joint != null && device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            var go        = joint.gameObject;
            var rigidbody = go.GetComponent <Rigidbody>();
            Object.DestroyImmediate(joint);
            joint = null;
            Object.Destroy(go, 15.0f);
            if (device.velocity.magnitude >= 0.5f)
            {
                AudioSource.PlayClipAtPoint(pp, go.transform.position, 1.0f);
            }
            // We should probably apply the offset between trackedObj.transform.position
            // and device.transform.pos to insert into the physics sim at the correct
            // location, however, we would then want to predict ahead the visual representation
            // by the same amount we are predicting our render poses.

            var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;
            if (origin != null)
            {
                rigidbody.velocity        = origin.TransformVector(device.velocity);
                rigidbody.angularVelocity = origin.TransformVector(device.angularVelocity);
            }
            else
            {
                rigidbody.velocity        = device.velocity;
                rigidbody.angularVelocity = device.angularVelocity;
            }

            rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude;
        }
    }
Ejemplo n.º 27
0
    void Start()
    {
        fixedJoint = GetComponent <FixedJoint>();

        if (grabPinchAction == null)
        {
            Debug.LogError("Grab pinch action not assigned!");
            return;
        }

        if (grabGripAction == null)
        {
            Debug.LogError("Grab grip action not assigned!");
            return;
        }

        grabPinchAction.AddOnChangeListener(OnGrabPinchChange, hand.handType);
        grabGripAction.AddOnChangeListener(OnGrabGripChange, hand.handType);
    }
Ejemplo n.º 28
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Ground"))
     {
         FixedJoint fixedJoint = gameObject.AddComponent(typeof(FixedJoint)) as FixedJoint;
         fixedJoint.connectedBody = collision.rigidbody;
         Physics.IgnoreCollision(thisCollider, collision.collider);
     }
     if (collision.collider.gameObject.layer == LayerMask.NameToLayer("Wall"))
     {
         FixedJoint fixedJoint = gameObject.AddComponent(typeof(FixedJoint)) as FixedJoint;
         fixedJoint.connectedBody = collision.rigidbody;
         Physics.IgnoreCollision(thisCollider, collision.collider);
     }
     if (collision.collider.gameObject.tag == "Hazard")
     {
         collision.collider.gameObject.SetActive(false);
     }
 }
Ejemplo n.º 29
0
    void GravityBeam()
    {
        renderer.material.mainTextureOffset = new Vector2(0, Time.time);

        Ray        ray = new Ray(transform.position, transform.forward);
        RaycastHit hit;


        line.SetPosition(0, ray.origin);


        // attempt to pickup
        if (Physics.Raycast(ray, out hit, laserMaxDistance))
        {
            line.SetPosition(1, hit.point);
            distance         = (hit.point - ray.origin).magnitude;
            ps.startLifetime = distance / 5;
            ps.startColor    = Color.blue;
            light.color      = Color.blue;

            objectParameters = hit.collider.gameObject.GetComponent <ObjectParameters>();

            while (hit.rigidbody && !jointedObject && objectParameters.canGravity == true)
            {
                Vector3 lastHit = hit.point;

                if (Input.GetButton("Fire1") || Input.GetButton("Fire2"))
                {
                    distance = (hit.point - ray.origin).magnitude;

                    jointedObject = hit.collider.gameObject.transform;
                    jointedJoint  = jointedObject.gameObject.AddComponent <FixedJoint>();
                    jointedJoint.connectedBody = GetComponent <Rigidbody>();
                    jointedJoint.autoConfigureConnectedAnchor = true;
                    jointedJoint.breakForce = jointBreakForce;
                }
            }
        }
        else
        {
            line.SetPosition(1, ray.GetPoint(laserMaxDistance));
        }
    }
Ejemplo n.º 30
0
    void AttachToHand(Rigidbody attachPoint)
    {
        Debug.Log("attached to hand");
        if (rb)
        {
            //rb.isKinematic = true;
            rb.useGravity    = false;
            rb.interpolation = RigidbodyInterpolation.None;
        }
        if (coll)
        {
            coll.enabled = false;
        }

        rb.MovePosition(attachPoint.transform.position - transform.position);

        joint = gameObject.AddComponent <FixedJoint>();
        joint.connectedBody = attachPoint;
    }