コード例 #1
0
ファイル: ViveController.cs プロジェクト: jhclaura/RigTest
    private void ExitGrabMode(bool destroyImmediate)
    {
        m_CurrentInteractible.Up(gameObject);

        if (objHasRigidbody)
        {
            var device    = SteamVR_Controller.Input((int)trackedObj.index);
            var obj       = joint.gameObject;
            var rigidbody = obj.GetComponent <Rigidbody> ();

            // destroy the fixed joint
            if (destroyImmediate)
            {
                UnityEngine.Object.DestroyImmediate(joint);
            }
            else
            {
                UnityEngine.Object.Destroy(joint);
            }
            joint = null;

            // Apply force
            var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent;
            if (origin != null)
            {
                // of grabbed obj
                rigidbody.velocity        = origin.TransformVector(device.velocity);           //transform vector from local to world space
                rigidbody.angularVelocity = origin.TransformVector(device.angularVelocity);
            }
            else
            {
                rigidbody.velocity        = device.velocity;
                rigidbody.angularVelocity = device.angularVelocity;
            }
            rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude;

            // Reset kinematic status
            if (objIsKinematic)
            {
                touchedObj.GetComponent <Rigidbody> ().isKinematic = true;
            }
        }
        else
        {
            touchedObj.transform.parent = null;
        }

        grabSomething = false;
        DeviceVibrate();
        Debug.Log(gameObject.name + " exits grab!");
    }
コード例 #2
0
ファイル: GrabnStretch.cs プロジェクト: jhclaura/ooni-tool
    private void ExitGrabMode(bool destroyImmediate)
    {
        //Debug.Log (gameObject.name + " exits grab!");
        //Debug.Log ("exits grab, device velocity: " + Device.velocity.sqrMagnitude);

        m_CurrentInteractible.Up(gameObject);

        if (m_CurrentInteractible.HasRigidbody)
        {
            Debug.Log("m_CurrentInteractible.HasRigidbody");
            // remote joint!
            if (m_CurrentInteractible.Joint != null)
            {
                var device    = Device;
                var rigidbody = m_CurrentInteractible.Joint.GetComponent <Rigidbody> ();

                // destroy the fixed joint
                m_CurrentInteractible.RemoveJoint();

                // Apply force
                rigidbody.velocity           = device.velocity;
                rigidbody.angularVelocity    = device.angularVelocity;
                rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude;
            }

            // Reset kinematic status
            if (m_CurrentInteractible.IsKinematic)
            {
                touchedObj.GetComponent <Rigidbody> ().isKinematic = true;
            }
        }
        else
        {
            if (touchedObj)
            {
                //touchedObj.transform.parent = null;
                touchedObj.transform.parent = stickerParent;

                if (m_CurrentInteractible.usePhysics && Device.velocity.sqrMagnitude > 0.2f)
                {
                    Rigidbody r_b = m_CurrentInteractible.AddRigidbody();
                    r_b.velocity        = Device.velocity;
                    r_b.angularVelocity = Device.angularVelocity;
                }
            }
        }

        grabSomething = false;
        //DeviceVibrate();
    }