aframe-extras icon indicating copy to clipboard operation
aframe-extras copied to clipboard

[gamepad-controls] Support rotation with secondary WebXR controller

Open simsim314 opened this issue 5 years ago • 6 comments

I'm using oculus quest and basically everything is working fine, but usually movement controls allow rotation not only with head movement but also with joystick. For seated situation it's not so pleasant to rotate the head, especially not for movement in space. While the right controller is responsible for the movement, it would be nice to have the left controller to have a rotation function. As far as I can tell it's shouldn't be a too complex of addition - I wanted to add it myself, but I'm not sure from where do I get the second joystick input (the rotation quaternion I can take from head rotation part).

simsim314 avatar Oct 08 '19 06:10 simsim314

Can you share how your controls are set up, and ideally a demo? Are you doing something like one of these examples? https://github.com/donmccurdy/aframe-extras/tree/master/src/controls#usage

In theory this is already supported, although it's more designed for the gamepad to be a fallback when head movement isn't available, rather than using both at the same time, and I don't 100% know if that will work. See https://github.com/donmccurdy/aframe-extras/blob/master/src/controls/gamepad-controls.js#L122-L165.

It's also possible that the underlying VR controller API has changed since I wrote this, or that the Quest controller is set up differently than other gamepads I've tested.

donmccurdy avatar Oct 13 '19 18:10 donmccurdy

Not sure if this addresses the topic, but this might be of interest anyhow.

I took the code for the Quest mainly from this example which implements the controls in a straight forward manner: https://github.com/TakashiYoshinaga/Oculus-Quest-Interaction-Sample

dirkk0 avatar Oct 20 '19 09:10 dirkk0

@donmccurdy Oculus Touch controls show up as two separate gamepads when in VR, and there does not appear any consistency as to which is listed first in the gamepads array. Your movement controls as currently written only support one controller at a time, so one hand is always inoperative.

paulmasson avatar Dec 06 '19 00:12 paulmasson

The movement-controls component delegates gamepad stuff to the gamepad-controls component. Within that component, these two functions are responsible for which controller and which joystick are chosen:

https://github.com/donmccurdy/aframe-extras/blob/3894e2d8c58bf029630a91d0d780e483ab102b80/src/controls/gamepad-controls.js#L237-L246

https://github.com/donmccurdy/aframe-extras/blob/3894e2d8c58bf029630a91d0d780e483ab102b80/src/controls/gamepad-controls.js#L273-L288

Those will take some reorganizing to support rotation by the second controller. I won't be able to work on that any time soon, but PRs would be welcome.

Inconsistent selection of the other gamepad is a different issue, since the whole thing was written before the WebXR spec introduced 'handedness' values that could be used as stable identifiers. Filed that as https://github.com/donmccurdy/aframe-extras/issues/313.

donmccurdy avatar Jan 17 '20 05:01 donmccurdy

@donmccurdy Most Oculus titles are set up to use the left stick as forward/backward and strafe, the right stick as rotate, a bit like 1st person gamepad controls albeit with heading direction / rotation factored in as you already have.

I wrote some very simple code to grab the left or right stick, not sure if this helps any, but would be great to use aframe-extras to do Oculus Touch movement.

This code doesn't factor in any heading rotation, it's just to show left / right stick clarification on Oculus Touch controllers (note how axis[] 0 and 1 are now ignored on Oculus Browser, they are 2(x) and 3(y) respectively):

el.addEventListener('axismove', function (event)
{
    if(el.getAttribute('oculus-touch-controls').hand == 'right')
    {
        rig.object3D.rotation.y -= (event.detail.axis[2] * rotationSpeed);
    }
    if(el.getAttribute('oculus-touch-controls').hand == 'left')
    {
        rig.object3D.position.z += (event.detail.axis[3] * movementSpeed);
        rig.object3D.position.x += (event.detail.axis[2] * movementSpeed);
    }
});```

HawkenKing avatar May 17 '20 18:05 HawkenKing

I am not sure how relevant this is, but something that comes to mind... When using this library with a basic 0dof (playstation/xbox-like) gamepad in cardboard, I have noticed that my 'fly' direction is correctly controlled relative to my cardboard's rotation input, but my rotation seems to be interpreted, added, and then immediately overridden almost completely. Sometimes the overriding isn't perfect and I get a slight change.

On the other hand, when using such a gamepad in desktop mode, the rotation input is correctly taken from the second joystick.

Allowing joystick rotation in VR is a pretty common feature for advanced users these days. In Echo Arena, for example, tapping that joystick allows quick changes in direction. I think in action-oriented VR titles (FPS, etc.), it's basicaly standard.

The library should probably be updated to allow this at a basic level in a way it seems designed explicitly not to currently.

kylebakerio avatar Jan 04 '21 12:01 kylebakerio