Example of navigation + interaction using VR?

Get world direction is a util method from needle engine. The rest is all threejs :slightly_smiling_face:

o_O thank you so much! I was doing something weird like GameObject.findObjectOfType(Camera) or GameObject.findObjectOfType(SyncedCamera) to get the camera :joy:

by user 832577308644212766

Working perfectly, just had to negate the direction dir.normalize().negate() :pray:

by user 832577308644212766

Find object of type Camera would get it as well but more expensive :slightly_smiling_face:

Instead of negate just multiply with negative Delta time to save a tiny bit :slightly_smiling_face:

Great to hear it works

ok!

by user 832577308644212766

So basically the XRRig doesn’t change orientation? It’s only the camera that changes?

by user 832577308644212766

You can also rotate the XR rig to rotate yourself in VR.

Or scale it to make you bigger or smaller

The camera is driven by the vr headset and parented to the xr rig object (its a child)

Yeah I mean when I move the head, the orientation of the XRRig stays the same, but the camera changes is that correct?

by user 832577308644212766

Yes

Got it!

by user 832577308644212766

You can maybe think of the xrrig as your playspace (not scaled to match the size tho)

For the rotation using right joystick I came up with this code. It basically works, although it causes a bit of motion sickness. Don’t know if it can improved

if (this.rightController) {            
            const axesX = this.rightController.input?.gamepad?.axes[2];            

            if (axesX) {
                const rotationVec = new Vector3(0, -1, 0);
                this.webXR?.Rig.rotateOnWorldAxis(rotationVec, axesX * this.context.time.deltaTime);
            }            
        }

by user 832577308644212766

Thats why we decided to move in steps. Like in https://castle.needle.tools - you can read the code for it in the WebXRController class if you want (its in the needle engine package)

It basically detects if the joystick goes over a threshold left or right once and then rotates in one frame by 30Β° or so. Instead of continuously a little bit every frame

You could do the same in your code by just multiplying it to be e.g. 30Β° (use Mathf.degree to radians) and then set a bool variable to true that you did just rotate. Now wait until the joystick is released (while your bool is true) before rotating again and then setting the bool to false again.

Thanks a lot for the explanation

by user 832577308644212766