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
1
Question by Gmoff01 · Oct 05, 2016 at 08:52 PM · guisliderinfinitedial

Infinite circular slider / rotary dial input

I want to implement an input that consists of a circle that the user would rotate like a dial to increment/decrement an associated number. I've been able to find a few posts about how to make a dial visually rotate when used like this, and I think I could figure out how to get a number from the resulting angle if the dial was limited to < 360 degrees of spin, but I want the user to be able to keep rotating the dial indefinitely to continue raising or lowering the associated number. I'm not entirely sure how to approach this, I'd appreciate any help to get started.

Thank you!

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

1 Reply

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

Answer by elenzil · Oct 05, 2016 at 09:17 PM

 float prevDegrees = 0;
 float cumulativeValue = 0;
 
 // assuming the "degrees" is guaranteed in the the range [-180, 180].
 void onNewDegrees(float degrees) {
     float diff = degrees - prevDegrees;
     if (diff > 180f) {
       diff -= 360f;
     }
     else if (diff < -180f) {
       diff += 360f;
     }
 
     cumulativeValue += diff;
 
     prevDegrees = degrees;
 }
 
Comment
Add comment · Show 5 · 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 elenzil · Oct 05, 2016 at 10:08 PM 0
Share

actually, this may work even if degrees is in the range [0, 360]. not sure.

avatar image Bunny83 elenzil · Oct 06, 2016 at 02:01 AM 1
Share

Yes, this does work with any range. The subtraction actually removes any offset that both values might have as they cancel out. The delta must never actually be larger than 180 or smaller than -180 as in that case the direction can not be deter$$anonymous$$ed / would be inverted. However at a decent framerate the user usually can't rotate fast enough to produce a delta larger than +-180.

avatar image elenzil Bunny83 · Oct 06, 2016 at 05:18 PM 0
Share

the only case i worry about is if the user runs their finger right through the center of the dial. in that scenario the delta might be more than +/- 180º. but it might be fair to call that user-error. ;)

actually i guess a really robust "knob" widget would have a maximum amount of change per frame, so if you go through the center it would only turn say a max of 30º per frame or something. i've never seen that implemented, tho.

avatar image Gmoff01 · Oct 06, 2016 at 09:41 PM 0
Share

This worked perfectly, just note that you need to reset the prevDegrees to the initial angle whenever the user touches the control or the value controlled by the dial can jump around a bit. Thanks much!

avatar image elenzil Gmoff01 · Oct 06, 2016 at 10:28 PM 0
Share

cool - glad that worked for you! yes, as you point out, "prevDegrees" should be reset on the beginning of input.

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

89 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

Related Questions

cant slide GUI slider 0 Answers

'MouseLook.sensitivityX' is inaccessible due to its protection level. 2 Answers

Use gui slider to change text field and vice versa? 1 Answer

Hover state doesn't work on slider with custom styles 0 Answers

How to change how meany decimals are in a GUI sound slider 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