unity 2019.2.3 oculus integration 13 and 14 I have a Mac and use the oculus quest
I can't even begin to guess whats wrong it worked one day and not the next. I was working with external scripts that accessed the grabble but it worked even then. distance grabbable and grabbable both aren't working. I can grab with each controller. Just can't off hand grab. which is how you grab object out of other hand thats holding the object right?
I tested to see if the allow off hand grab bool changed to false when I grabbed an object and it doesn't. I reimported the grabber, grabbable and distance grabbable.
*************************************************Heres the grabber script
/************************************************************************************ Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use the Utilities SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ************************************************************************************/
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
/// <summary> /// Allows grabbing and throwing of objects with the OVRGrabbable component on them. /// </summary> [RequireComponent(typeof(Rigidbody))] public class OVRGrabber : MonoBehaviour {
[HideInInspector] public bool inhand; // Grip trigger thresholds for picking up objects, with some hysteresis. public float grabBegin = 0.55f; public float grabEnd = 0.35f;
bool alreadyUpdated = false;
// Demonstrates parenting the held object to the hand's transform when grabbed. // When false, the grabbed object is moved every FixedUpdate using MovePosition. // Note that MovePosition is required for proper physics simulation. If you set this to true, you can // easily observe broken physics simulation by, for example, moving the bottom cube of a stacked // tower and noting a complete loss of friction. [SerializeField] protected bool m_parentHeldObject = false;
// If true, will move the hand to the transform specified by m_parentTransform, using MovePosition in // FixedUpdate. This allows correct physics behavior, at the cost of some latency. // (If false, the hand can simply be attached to the hand anchor, which updates position in LateUpdate, // gaining us a few ms of reduced latency.) [SerializeField] protected bool m_moveHandPosition = false;
// Child/attached transforms of the grabber, indicating where to snap held objects to (if you snap them). // Also used for ranking grab targets in case of multiple candidates. [SerializeField] protected Transform m_gripTransform = null; // Child/attached Colliders to detect candidate grabbable objects. [SerializeField] protected Collider[] m_grabVolumes = null;
// Should be OVRInput.Controller.LTouch or OVRInput.Controller.RTouch. [SerializeField] protected OVRInput.Controller m_controller;
public OVRInput.Controller GetController() { return m_controller; }
if(!m_moveHandPosition) { // If we are being used with an OVRCameraRig, let it drive input updates, which may come from Update or FixedUpdate. OVRCameraRig rig = transform.GetComponentInParent<OVRCameraRig>(); if (rig != null) { rig.UpdatedAnchors += (r) => {OnUpdatedAnchors();}; m_operatingWithoutOVRCameraRig = false; } } }
protected virtual void Start() { m_lastPos = transform.position; m_lastRot = transform.rotation; if(m_parentTransform == null) { if(gameObject.transform.parent != null) { m_parentTransform = gameObject.transform.parent.transform; } else { m_parentTransform = new GameObject().transform; m_parentTransform.position = Vector3.zero; m_parentTransform.rotation = Quaternion.identity; } } // We're going to setup the player collision to ignore the hand collision. SetPlayerIgnoreCollision(gameObject, true); }
virtual public void Update() { alreadyUpdated = false;
}
virtual public void FixedUpdate() { if (m_operatingWithoutOVRCameraRig) { OnUpdatedAnchors(); } }
// Hands follow the touch anchors by calling MovePosition each frame to reach the anchor. // This is done instead of parenting to achieve workable physics. If you don't require physics on // your hands or held objects, you may wish to switch to parenting. void OnUpdatedAnchors() { // Don't want to MovePosition multiple times in a frame, as it causes high judder in conjunction // with the hand position prediction in the runtime. if (alreadyUpdated) return; alreadyUpdated = true;
// Note: force teleport on grab, to avoid high-speed travel to dest which hits a lot of other objects at high // speed and sends them flying. The grabbed object may still teleport inside of other objects, but fixing that // is beyond the scope of this demo. MoveGrabbedObject(m_lastPos, m_lastRot, true); SetPlayerIgnoreCollision(m_grabbedObj.gameObject, true); if (m_parentHeldObject) { m_grabbedObj.transform.parent = transform; inhand = true;
protected void SetPlayerIgnoreCollision(GameObject grabbable, bool ignore) { if (m_player != null) { Collider[] playerColliders = m_player.GetComponentsInChildren<Collider>(); foreach (Collider pc in playerColliders) { Collider[] colliders = grabbable.GetComponentsInChildren<Collider>(); foreach (Collider c in colliders) { Physics.IgnoreCollision(c, pc, ignore); } } } } }
*****************************************************Heres the grabbable script
/************************************************************************************ Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use the Utilities SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ************************************************************************************/
using System; using UnityEngine;
/// <summary> /// An object that can be grabbed and thrown by OVRGrabber. /// </summary> public class OVRGrabbable : MonoBehaviour { [SerializeField] protected bool m_allowOffhandGrab = true; [SerializeField] protected bool m_snapPosition = false; [SerializeField] protected bool m_snapOrientation = false; [SerializeField] protected Transform m_snapOffset; [SerializeField] protected Collider[] m_grabPoints = null;
/// <summary> /// If true, the object can currently be grabbed. /// </summary> public bool allowOffhandGrab { get { return m_allowOffhandGrab; } }
/// <summary> /// If true, the object is currently grabbed. /// </summary> public bool isGrabbed { get { return m_grabbedBy != null; } }
/// <summary> /// If true, the object's position will snap to match snapOffset when grabbed. /// </summary> public bool snapPosition { get { return m_snapPosition; } }
/// <summary> /// If true, the object's orientation will snap to match snapOffset when grabbed. /// </summary> public bool snapOrientation { get { return m_snapOrientation; } }
/// <summary> /// An offset relative to the OVRGrabber where this object can snap when grabbed. /// </summary> public Transform snapOffset { get { return m_snapOffset; } }
/// <summary> /// Returns the OVRGrabber currently grabbing this object. /// </summary> public OVRGrabber grabbedBy { get { return m_grabbedBy; } }
/// <summary> /// The transform at which this object was grabbed. /// </summary> public Transform grabbedTransform { get { return m_grabbedCollider.transform; } }
/// <summary> /// The Rigidbody of the collider that was used to grab this object. /// </summary> public Rigidbody grabbedRigidbody { get { return m_grabbedCollider.attachedRigidbody; } }
/// <summary> /// The contact point(s) where the object was grabbed. /// </summary> public Collider[] grabPoints { get { return m_grabPoints; } }
/// <summary> /// Notifies the object that it has been grabbed. /// </summary> virtual public void GrabBegin(OVRGrabber hand, Collider grabPoint) { m_grabbedBy = hand; m_grabbedCollider = grabPoint; gameObject.GetComponent<Rigidbody>().isKinematic = true; }
/// <summary> /// Notifies the object that it has been released. /// </summary> virtual public void GrabEnd(Vector3 linearVelocity, Vector3 angularVelocity) { Rigidbody rb = gameObject.GetComponent<Rigidbody>(); rb.isKinematic = m_grabbedKinematic; rb.velocity = linearVelocity; rb.angularVelocity = angularVelocity; m_grabbedBy = null; m_grabbedCollider = null; }
void Awake() { if (m_grabPoints.Length == 0) { // Get the collider from the grabbable Collider collider = this.GetComponent<Collider>(); if (collider == null) { throw new ArgumentException("Grabbables cannot have zero grab points and no collider -- please add a grab point or collider."); }
// Create a default grab point m_grabPoints = new Collider[1] { collider }; } }
I figured it out. The distance grabber doesn't allow offhand grab at least in the distance scene which is dumb or a bug. I had to add the grabber component under the distance grabber component and transfer over what I could from the distance grabber to the ovr grabber component. But all of that worked on the distance grabber scene. I just gotta figure out why its not working in my scene or I need o transfer everything over from one to the other scene.