Control of the left hand
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
[Requirecomponent (typeof (Steamvr_trackedobject))]
public class Leftss:monobehaviour {
Steamvr_trackedobject Trackedobj;
Steamvr_controller.device Device;
Public Transform sphere;//Reset feature
void Awake () {
Trackedobj = getcomponent<steamvr_trackedobject> ();
}
void Fixedupdate () {
device = Steamvr_controller.input ((int) trackedobj.index);
if (device. Gettouch (SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log ("Touch Trigger");
}
if (device. Gettouchdown (SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log ("Touchdown Trigger");
}
if (device. Gettouchup (SteamVR_Controller.ButtonMask.Trigger)) {
Debug.Log ("TouchUp Trigger");
}
Drag the object into the Reset function
if (device. Getpressup (SteamVR_Controller.ButtonMask.Touchpad)) {
Sphere.transform.position = Vector3.zero;
Sphere. Getcomponent<rigidbody> (). Velocity = Vector3.zero;
Sphere. Getcomponent<rigidbody> (). angularvelocity = Vector3.zero;
}
}
void Ontriggerstay (Collider collider)
{
Item Crawl
if (device. Gettouch (SteamVR_Controller.ButtonMask.Trigger)) {
Collider.attachedRigidbody.isKinematic = true;
Collider.gameObject.transform.SetParent (Gameobject.transform);
}
Goods separation
if (device. Gettouchup (SteamVR_Controller.ButtonMask.Trigger)) {
Collider.attachedRigidbody.isKinematic = false;
Collider.gameObject.transform.SetParent (NULL);
Tossobject (Collider.attachedrigidbody);
}
}
Goods throw
void Tossobject (Rigidbody rigidbody)
{
Transform orgin = Trackedobj.origin? TrackedObj.origin:trackedObj.transform.parent;
if (orgin!= null) {
Rigidbody.velocity = Orgin. Transformvector ((device.velocity));
Rigidbody.angularvelocity = Orgin. Transformvector (device.angularvelocity);
} else
{
rigidbody.velocity = device.velocity;
rigidbody.angularvelocity = device.angularvelocity;
}
rigidbody.velocity = device.velocity;
rigidbody.angularvelocity = device.angularvelocity;
}
}
Control of the right hand
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine;
[Requirecomponent (typeof (Steamvr_trackedobject))]
public class Rightss:monobehaviour {
The tracking device, that's our handle.
Steamvr_trackedobject Trackedobj;
Get input from a handle
Steamvr_controller.device Device;
Fixed joint
Fixedjoint Fixedjoint;
A rigidbody located on a handle
Public Rigidbody Rigidbodyattachpoint;
public Transform Sphere;
void Awake () {
Trackedobj = getcomponent<steamvr_trackedobject> ();
}
void Fixedupdate () {
device = Steamvr_controller.input ((int) trackedobj.index);
Resetting features
if (device. Getpressup (SteamVR_Controller.ButtonMask.Touchpad)) {
Position
Sphere.transform.position = Vector3.zero;
Speed
Sphere. Getcomponent<rigidbody> (). Velocity = Vector3.zero;
Angular Velocity
Sphere. Getcomponent<rigidbody> (). angularvelocity = Vector3.zero;
}
}
void Ontriggerstay (Collider collider)
{
if (Fixedjoint = = null && device. Gettouch (SteamVR_Controller.ButtonMask.Trigger)) {
To add a joint component to the instantiated object, the position of the connection is this rigidbody
Fixedjoint = collider.gameobject.addcomponent<fixedjoint> ();
Fixedjoint.connectedbody = Rigidbodyattachpoint;
else if (fixedjoint!= null && device. Gettouchup (SteamVR_Controller.ButtonMask.Trigger)) {
Get the game object on the joint
Gameobject go = fixedjoint.gameobject;
Get a Rigidbody
Rigidbody rigidbody = go. Getcomponent<rigidbody> ();
Destroyed
Object.destroy (Fixedjoint);
Set to NULL
Fixedjoint = null;
Tossobject (Rigidbody);
}
}
void Tossobject (Rigidbody rigidbody)
{
Transform orgin = Trackedobj.origin? TrackedObj.origin:trackedObj.transform.parent;
if (orgin!= null) {
Rigidbody.velocity = Orgin. Transformvector ((device.velocity));
Rigidbody.angularvelocity = Orgin. Transformvector (device.angularvelocity);
} else {
rigidbody.velocity = device.velocity;
rigidbody.angularvelocity = device.angularvelocity;
}
}
}