SpaceUnicorn
SpaceUnicorn

Reputation: 11

How do I get the Vive controller Transform component from SteamVR 2.0 for a Unity project?

I'm currently developing an AR application in Unity using the Zed mini camera. The Zed SDK comes with a Zed_Controller_Tracker script which you attach to a gameobject in order to have that object tracked to the chosen device (in this case, a controller). Unfortunately, the script is not adequate for my needs. The attached object often drifts off or jitters and does not return to the appropriate location. This suggests that it is a tracking issue, possibly on my end. As a work around, I want to write my own script which will get the controller position and attach the object to the controller.

pseudo code:

SteamVR_Controller controller;
GameObject trackedObject;

void update(){
    trackedObject.position = controller.GetComponent(Transform()).position;
}

The above is how simple the code should be. The problem I'm facing is that in SteamVR 2.0, there is no such thing as a SteamVR_Controller. I've looked and I'm unable to find anything that would allow me to define a controller object. In steamvr 2.0 there is a thing called SteamVR_Behaviour_Pose which 'Add this to a GameObject to automatically set the position and rotation of the transform to match your tracked object (usually controllers).' This sounds like the exact thing I want, except that it does not work the way I need it to. I create my object to be tracked, attach the script, set the input source as right hand, and the object is tracked, only it has a slight offset. I've tried parenting the object in order to fix the offset so that it is centered, but parenting the object causes other issues with the script that result in unwanted behaviour (object tracked to the floor rather than controller).

In the end, the only solution I can come up with that suits my needs is to make my own script but I need to know how to call a controller.position with steamVR 2.0 and this doesn't appear to be an easy task. Please help :)

Note: Using the controller prefab does not work as there is an offset between the zed mini and the vr world. Basically the AR (real) controller is slightly to the right of the VR controller and when I adjust this offset such that the two are superimposed, the new problem is that the arc of rotation for the two are not the same. moving the controller 90 degrees moves both the same, but not along the same arc which results in a new offset between the two. A script could be written to account for this, but I expect it would be quite complicated and simply lead to more troubles.

Upvotes: 1

Views: 1059

Answers (0)

Related Questions