Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
CaptainNemo7's avatar
CaptainNemo7
Explorer
4 years ago

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
  • Interaction SDK is broken with most of UI elements. InputFields are not working at all since v41

  • 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

  • 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;
                }
            }
        }
    • RedShed's avatar
      RedShed
      Explorer

      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;