- Home /
Question by
georgia_xyl · Aug 03, 2021 at 11:36 AM ·
vroculus
Grab and move object with gaze pointer oculus quest 2
I want to grab an object with gaze pointer in oculus quest 2. i dont want to grab it with controllers but with the gaze and control it with the movement of the head. can anybody help me?
Comment
Answer by rh_galaxy · Aug 03, 2021 at 12:17 PM
Vector3 vHeadPosition = Camera.main.transform.position;
Vector3 vGazeDirection = Camera.main.transform.forward;
Physics.Raycast(vHeadPosition, vGazeDirection, out oHitInfo, 400.0f)
This should work with any platform as long as you have the main camera at the real head position. This should work with Unity 2021.1.6f1 and the new XR system:
//to be used in start
UnityEngine.XR.InputDevice handRDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
UnityEngine.XR.InputDevice handLDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
UnityEngine.XR.InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
//to be used in update
bool posRSupported = headDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.devicePosition, out Vector3 posR);
vHeadPosition = transform.TransformPoint(posR); //to world coords
bool rotRSupported = headDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.deviceRotation, out Quaternion rotR);
vGazeDirection = rotR * Vector3.forward;
vGazeDirection = transform.TransformDirection(vGazeDirection);
//qRotation = Quaternion.LookRotation(vGazeDirection);
Your answer
![](https://koobas.hobune.stream/wayback/20220613041147im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
black spot issue for a friction of a second for left/right eye while head movement on oculus go 0 Answers
How do I get the Oculus Rift's headset's position and rotation? 1 Answer
Oculus VR with Mirror multiplayer - headset is controlling both players 1 Answer
How to enable 6DOF for VR game? 1 Answer