Is it possible to calculate the ray from the center of an XR headset

I’m working on an XR game that’s playable without a controller. As part of it, I need to calculate a ray from the center of the headset for firing a projectile. Is there any way of doing this?

I haven’t actually tested it, but I think the code would work.

    // enable xr
    let xr = await BABYLON.WebXRExperienceHelper.CreateAsync(scene);

    // on input
    let ray =
    let { origin, direction } = ray
    // do something