public virtual void Detach() { m_attached = false; m_device = null; m_handObject = null; m_transform.SetParent(null, true); if (m_rigidbody != null) { m_rigidbody.isKinematic = !m_dynamic; Vector3 deltaPos = m_transform.position - m_previousPosition; Vector3 newVel = deltaPos / Time.deltaTime; m_rigidbody.AddForce(newVel, ForceMode.VelocityChange); /* * Quaternion deltaRot = Quaternion.Inverse(m_transform.rotation) * m_previousRotation; * Vector3 newTorque = deltaRot.eulerAngles / Time.deltaTime; * * m_rigidbody.AddTorque(newTorque, ForceMode.VelocityChange); */ Vector3 x = Vector3.Cross(m_previousForward, m_transform.forward); float theta = Mathf.Asin(x.magnitude); Vector3 w = x.normalized * theta / Time.fixedDeltaTime; Quaternion q = transform.rotation * m_rigidbody.inertiaTensorRotation; Vector3 newTorque = q * Vector3.Scale(m_rigidbody.inertiaTensor, (Quaternion.Inverse(q) * w)); m_rigidbody.AddTorque(newTorque, ForceMode.Impulse); } }
public virtual bool Attach(Transform parent, InteractableHand hand, int deviceIndex, bool worldPositionStays) { if (m_attached) { return(false); } m_attached = true; #if !UNITY_EDITOR_OSX m_device = SteamVR_Controller.Input(deviceIndex); m_transform.SetParent(parent, worldPositionStays); m_handObject = hand; if (!worldPositionStays) { m_transform.localPosition = Vector3.zero; m_transform.localRotation = Quaternion.identity; } if (m_rigidbody != null) { m_rigidbody.isKinematic = true; } #endif return(true); }
public override bool Attach(Transform parent, InteractableHand hand, int deviceIndex, bool worldPositionStays) { bool attach = base.Attach(parent, hand, deviceIndex, worldPositionStays); m_collider.isTrigger = true; return(attach); }