- Home /
Question by
shmoon2917 · Jun 12, 2017 at 10:04 AM ·
vrsteamfixedjoint
SteamVR with VIVE : How can I drag object only Y transformation?
Hello-
I'm trying to make a virtual reality game using vive controller and unity.
I already implemented function that can hold, drag, and throw the object using 'Fixedjoint' component. but I have some problem about dragging the drawer object.
When I hold and drag the drawer using controller, conflict occurs between drawer and desk that including drawer. It is because drawer's position is all changed (x, y and z all things).
So my question is:
How can I drag object only Y transformation even if position of Vive controller is changed all x, y ,z axis?
private void GrabObject(){
//1
objectInHand = collidingObject;
collidingObject = null;
//2
var joint = AddFixedJoint();
joint.connectedBody = objectInHand.GetComponent<Rigidbody> ();
}
private FixedJoint AddFixedJoint(){
FixedJoint fx = gameObject.AddComponent<FixedJoint> ();
fx.breakForce = 20000000;
fx.breakTorque = 20000000;
return fx;
}
private void ReleaseObject()
{
if (GetComponent<FixedJoint> ()) {
GetComponent<FixedJoint>().connectedBody = null;
Destroy (GetComponent<FixedJoint> ());
objectInHand.GetComponent<Rigidbody>().velocity = Controller.velocity*10;
objectInHand.GetComponent<Rigidbody> ().angularVelocity = Controller.angularVelocity*10;
}
objectInHand = null;
}
Comment