0

I would like to attach together two Grabbed objects.

For this I need to know the gameobjects that are being manipulated so I can add a joint component.

The biggest problem I have at the moment is getting to the gameobjects that are being Grabbed.

I tried using GetGrabbedObject() but I only get "null".

From my limited understanding :

private GameObject ControllerL 

ControllerL = VRTK_DeviceFinder.GetControllerLeftHand(); // this should get me the left hand 

GameObject GO;

GO = ControllerL.GetComponent<VRTK_InteractGrab>().GetGrabbedObject(); // this should get me the gameobject Grabbed by the left hand

Anything else I am missing?

Programmer
  • 121,791
  • 22
  • 236
  • 328
wheric
  • 1
  • have you met all of the requirements outlined here: [https://vrtoolkit.readme.io/docs/vrtk_interactgrab](https://vrtoolkit.readme.io/docs/vrtk_interactgrab) – lockstock Sep 26 '17 at 04:10
  • VRTK_ControllerEvents on the controller : check VRTK_InteractTouch on the controller : check Interactable object has isGrabbable set to true : check I can grab the object in game no problem. I just can't get the name of the grabbed object. Tried bits of code from tutorials all over the web that contained "GetGrabbedObject" so I'm starting to wonder if it really is what I am looking for... – wheric Sep 26 '17 at 07:40

1 Answers1

0

This works.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;

public class JoinObjects : MonoBehaviour {

public GameObject GO1, GO2;
public GameObject ControllerL;
public GameObject ControllerR;
public GameObject GO;


// Use this for initialization
void Start ()
{
    GetComponent<VRTK_InteractableObject>().InteractableObjectGrabbed += new InteractableObjectEventHandler(ObjectGrabbed);
    GetComponent<VRTK_InteractGrab>().GetGrabbedObject();
}

private void ObjectGrabbed(object sender, InteractableObjectEventArgs e)
{
    Debug.Log("Im Grabbed");
}

public void Click()
{
    Debug.Log("pouet");

    ControllerL = VRTK_DeviceFinder.GetControllerLeftHand();
    ControllerR = VRTK_DeviceFinder.GetControllerRightHand();

    GO1 = ControllerL.GetComponent<VRTK_InteractGrab>().GetGrabbedObject();
    GO2 = ControllerR.GetComponent<VRTK_InteractGrab>().GetGrabbedObject();

    if (GO1 != null)
    {
        Debug.Log(GO1.name);
    }

    if (GO2 != null)
    {
        Debug.Log(GO2.name);
    }

    ConfigurableJoint CJoint;
    CJoint = GO1.AddComponent<ConfigurableJoint>();
    CJoint.connectedBody = GO2.GetComponent<Rigidbody>();
    //CJoint.angularXMotion = ConfigurableJointMotion.Locked;
    //CJoint.angularYMotion = ConfigurableJointMotion.Locked;
    //CJoint.angularZMotion = ConfigurableJointMotion.Locked;
    CJoint.xMotion = ConfigurableJointMotion.Locked;
    CJoint.yMotion = ConfigurableJointMotion.Locked;
    CJoint.zMotion = ConfigurableJointMotion.Locked;
}

}

wheric
  • 1