Forum Discussion
CaptainNemo7
4 years agoExplorer
Oculus Interaction SDK scrolling with thumbstick
Hey currently with the interaction sdk I am able to scroll with a click and drag with the primary button. I have not been able to find a way to just scroll with the joystick. Has anyone been able to fix this/find this?
5 Replies
Replies have been turned off for this discussion
- mecadiego113Explorer
Interaction SDK is broken with most of UI elements. InputFields are not working at all since v41
- CaptainNemo7Explorer
how are you or others getting around this?
- RedShedExplorer
I was actually quite close to implementing a feature for scrolling via thumbstick, but ultimately decided against it, since it doesn't really fit into my app.
But in a nutshell, that's how I would do it (in pseudocode):
1. Create a script and attach it to a scrolview.
2. OnPointerEnter -> triggerStays = true;
3. OnPointerExit -> triggerStays = false;
(For detecting whether you are currently pointing at the viewport)
4. Void update() -> if triggerStays = true execute following code:
var thumbstickposition = OVRInput.getThumbstickposition;
scrollRect.verticalNormalizedPosition = scrollRect.verticalNormalizedPosition + ( (- sthumbstickPosition) * scrollingSpeed);
A short explenation: the scrollrect can be manually moved via scrollRect.verticalNormalizedPosition = xyz.
When the thumbstick is up, it will return the value of 1. if it's down, it will return the value of -1. That means, if the thumbstick is down, you'll be subtracting a number from the verticalNormalizedPosition each frame, moving the scrollview up. And the opposite for the other direction. Cool part is, that youll be able to scroll faster the farther you go from the thumbstick center.
Fell free to ask me for a code implementation - Anton111111Expert Protege
My solution:
private bool _hovered = false; private bool _scrolling = false; private void Update() { if (_hovered || _scrolling) { var primary = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick); var secondary = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick); var range = (secondary.y != 0) ? secondary.y : (primary.y != 0) ? primary.y : 0; if (range != 0) { _scrolling = true; _recyclableScrollRect.verticalNormalizedPosition += range * 0.03f; } else { _scrolling = false; } } }- RedShedExplorer
Anton111111 wrote:
My solution:
private bool _hovered = false; private bool _scrolling = false; private void Update() { if (_hovered || _scrolling) { var primary = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick); var secondary = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick); var range = (secondary.y != 0) ? secondary.y : (primary.y != 0) ? primary.y : 0; if (range != 0) { _scrolling = true; _recyclableScrollRect.verticalNormalizedPosition += range * 0.03f; } else { _scrolling = false; } } }I think you could even add a * Time.deltaTime to the code to make the scrolling speed frame rate independent.
Something like this:_recyclableScrollRect.verticalNormalizedPosition += range * 0.03f * Time.deltaTime;
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 2 years ago