Hey there,
I am currently loosing my mind about something that I thought would be super simple. I want to get the velocity vector (or position vector) of my Oculus Quest 2 controller so I can use it in my code. Currently I am trying to do this with XRNodeStates (Unity - Scripting API: XR.XRNodeState.TryGetVelocity). However I just can’t figure out a way how to make it work - I am a complete beginner sorry.
What would the code be for this? If you could help me out that would be great!
All the best,
Yves
Hey,
It works for me. I found it there:
https://www.reddit.com/r/learnVRdev/comments/n5e8tm/how_to_use_controller_velocity_in_unity_xr/
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
public class ControllerVelocity : MonoBehaviour
{
InputDevice LeftControllerDevice;
InputDevice RightControllerDevice;
Vector3 LeftControllerVelocity;
Vector3 RightControllerVelocity;
void Start()
{
LeftControllerDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
RightControllerDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
}
void Update()
{
UpdateInput();
}
UpdateInput()
{
LeftControllerDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out LeftControllerVelocity);
RightControllerDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out RightControllerVelocity);
}
}