How To Get Acceleration From Motion Controller?

Hi,
I´m trying to get the acceleration from the motion controllers. I´m using only the XR API from Unity, because I want to keep it functional for all VR headsets.

With the following code I get just 0,0 back. Does anybody know how to archieve the correct value?

void Start () {
        nodeStates = new List<XRNodeState>();
        List<XRNodeState> tempStates = new List<XRNodeState>();
        InputTracking.GetNodeStates(tempStates);

       
        foreach (XRNodeState state in tempStates)
        {
            if (state.nodeType == XRNode.LeftHand || state.nodeType == XRNode.RightHand)
                nodeStates.Add(state);
        }

        InputDevice right = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
    }
     void Update () {

        foreach(XRNodeState node in nodeStates)
        {
            Vector3 acc = new Vector3();
            if(node.TryGetAcceleration(out acc))
                print(node.nodeType + " " + acc);
        }
    }

Unfortunally there seems not to be a solution.
I´m using now a script from another user, he used for throwing objects in VR. See here.

My script is used for movement of the player, by accelerate / shaking the motion controllers. Here is my solution, if anybody needs it.

public class Accelerometer : AController {

    private MeasureRotationVelocity right;
    private MeasureRotationVelocity left;
    private Quaternion previousRotation;

    public float movementSpeed;
 

    void Start () {
        GameObject rightController = GameObject.FindGameObjectWithTag("RightHand");
        GameObject leftController = GameObject.FindGameObjectWithTag("LeftHand");

        right = rightController.AddComponent<MeasureRotationVelocity>();
        left = leftController.AddComponent<MeasureRotationVelocity>();

        right.movementSpeed = movementSpeed;
        left.movementSpeed = movementSpeed;
    }
     void Update () {

        float velocity = right.velocity + left.velocity;

        if (velocity > 25)
            velocity /= 2;

        if(velocity > 10)
            MoveForward(velocity / 10);

    }


    public class MeasureRotationVelocity : MonoBehaviour
    {
        private Quaternion previousRotation;

        public float movementSpeed;
        public float velocity;

        void Update()
        {
            Quaternion deltaRotation = transform.rotation * Quaternion.Inverse(previousRotation);

            previousRotation = transform.rotation;

            float angle = 0.0f;
            Vector3 axis = Vector3.zero;

            deltaRotation.ToAngleAxis(out angle, out axis);

            angle *= Mathf.Deg2Rad;

            var angularVelocity = axis * angle * (movementSpeed / Time.deltaTime);
            velocity = angularVelocity.x;

            if (velocity < 0)
                velocity = velocity * -1;
        }
    }
}
1 Like