Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by patrickabroad · Aug 02, 2017 at 01:38 PM · c#vrscrollingcircletouchpad

Menu scrolling with Vive Touchpad?

Maybe I'm using the wrong terms but I can't seem to find anything.

I have a menu with a long list. I would like to be able to scroll through the list using a circular motion on the Vive touchpad.

I know how to divide the touchpad into quads (i.e. upper right, lower right, lower left, upper left) but I would like to add more "slices to the pie".

Can someone tell me how that's done or point me to a good tutorial?

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by patrickabroad · Aug 02, 2017 at 08:36 PM

Figured it out. Posting it for others and to close the question.

If you think of the touchpad as a pie, then you are simply trying to find out which slice of the pie the finger is touching. So you need to convert the XY coordinates into an Angle (from the center of the touchpad) and that will let you know which slice of the pie you are touching (i.e. if the Angle is from 0 - 45 degrees, you are on Slice 1, 45 - 90 degrees = slice 2, 90 - 135 degrees = slice 3, etc.).

So to calculate the angle from the center, we bust out our 9th grade algebra. Anyone remember SOH-CAH-TOA? The X coordinate on the touchpad is the Adjacent length and the Y coordinate is the Opposite length so you use Tan.

Angle = Inverse_Tan(y/x) of in Unity C#: Mathf.Atan (y / x) But that returns radians so you have to do a bit more to convert XY coordinates to degrees:

 float angle = (Mathf.Atan (y / x)) * (180 / Mathf.PI);

Here's my script. I have my touchpad divided into 8 slices:

 private int oldSlice;
 
 void Update {
          //determine which slice the player is touching at the start
          if (controller.GetTouchDown (touchpadBtn) & canvasActive) {
         float x = controller.GetAxis (touchpadBtn).x;
         float y = controller.GetAxis (touchpadBtn).y;
         float angle = (Mathf.Atan (y / x)) * (180 / Mathf.PI);
 
         if (x > 0) {
             if (y > 0) {
                 if (angle >= 45f) {
                     oldSlice= 1;
                 } else {
                     oldSlice= 2;
                 }
             } else {
                 if (-angle <= 45f) {
                     oldSlice= 3;
                 } else {
                     oldSlice= 4;
                 }
             }
         } 
         else {
             if (y < 0) {
                 if (angle >= 45f) {
                     oldSlice= 5;
                 } else {
                     oldSlice= 6;
                 }
             } else {
                 if (-angle <= 45f) {
                     oldSlice= 7;
                 } else {
                     oldSlice= 8;
                 }
             }
         }
     }
 
         //determine which slice the finger is currently on
     if (controller.GetTouch (touchpadBtn) & canvasActive) {
         float x = controller.GetAxis (touchpadBtn).x;
         float y = controller.GetAxis (touchpadBtn).y;
         float angle = (Mathf.Atan (y / x)) * (180 / Mathf.PI);
         int newSlice;
         //determine which piece of the pie the thumb is in
         if (x > 0) {
             if (y > 0) {
                 if (angle >= 45f) {
                     newSlice= 1;
                 } else {
                     newSlice= 2;
                 }
             } else {
                 if (-angle <= 45f) {
                     newSlice= 3;
                 } else {
                     newSlice= 4;
                 }
             }
         } 
         else {
             if (y < 0) {
                 if (angle >= 45f) {
                     newSlice= 5;
                 } else {
                     newSlice= 6;
                 }
             } else {
                 if (-angle <= 45f) {
                     newSlice= 7;
                 } else {
                     newSlice= 8;
                 }
             }
         }
 
 //if the current slice (newSlice) is different than the previous slice (oldSlice), do something
         if (newSlice!= oldSlice) {
             if (newSlice> oldSlice) {
                 if (newSlice == 8 && oldSlice== 1) {
                     if (menuState > 1) {
                         controller.TriggerHapticPulse (500);
                         menuState = menuState - 1;
                         StartCoroutine (RotateMe (18, 0.2f));
                     }
                 } else {
                     controller.TriggerHapticPulse (500);
                     menuState = menuState + 1;
                     StartCoroutine (RotateMe (-18, 0.2f));
                 }
             } else {
                 if (newSlice == 1 && oldSlice== 8) {
                     controller.TriggerHapticPulse (500);
                     menuState = menuState + 1;
                     StartCoroutine (rotateMenu (-18, 0.2f));
                 } else {
                     if (menuState > 1) {
                         controller.TriggerHapticPulse (500);
                         menuState = menuState - 1;
                         StartCoroutine (rotateMenu (18, 0.2f));
                     }
                 }
             }
             oldSlice = newSlice;
         }
     }
 }

I know I kind of brute forced this and I'm sure that someone is going to reply with like a one-line code that does all this but, until then, I hope this unsticks some people.

Cheers.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image patrickabroad · Aug 06, 2017 at 03:02 PM 0
Share

Apologies: I cut this chunk out of a bigger script and there are some unexplained variables in there. Just FYI: canvasActive is a bool to deter$$anonymous$$e if the menu is turned on, menuState is a public static int that triggers other actions in the game, and the coroutine rotate$$anonymous$$enu animates the menu between states.

Cheers.

avatar image
0

Answer by Bieere · Aug 02, 2017 at 06:48 PM

What you'll essentially need to do is calculate the delta for the trackpad location and send that information out to the IScrollHandler Events, or OnScroll assuming you're attempting to send it UGUI objects.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

382 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Htc Vive can't get axis from touchpad input 2 Answers

Steam VR touchpad to rotate object 1 Answer

Odd discrepancy with EulerAngles (Circular motion, C#) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges