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 operand · Jun 23, 2011 at 12:47 PM · rotationrigidbodycontrolsdial

Emulating a physical dial

Hello,

I am trying to replicate a physical dial/potentiometer like that which would be found on a synthesizer. So far I am able to rotate a rigidbody cylinder around freely on its x-axis with the z and y locked using the 'drag rigid body' script, but I need to limit its rotation to something like -45 to 45, so it has a 'min' and 'max' value which it can not exceed instead of spinning endlessly.

ANY help or advice would be appreciated, thanks

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
1

Answer by Meltdown · Jun 23, 2011 at 01:39 PM

You can do something something simple in your script like this to limit the rotation...

 float currentRotation;
 
 void FixedUpdate()
 {
   currentRotation = rigidbody.transform.eulerAngles.x;
 
   if(currentRotation < -45)
     rigidbody.transform.eulerAngles.x = -45;
   else if(currentRotation > 45)
     rigidbody.transform.eulerAngles.x = 45; 
 }

this code is not tested but you get the idea...

Comment
Add comment · Show 2 · 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 sneftel · Jun 23, 2011 at 02:19 PM 0
Share

You can also use $$anonymous$$athf.Clamp for the same thing (but in fewer lines).

avatar image operand · Jun 25, 2011 at 05:36 AM 0
Share

Thanks for the script $$anonymous$$eltdown, and cheers for the suggestion Ben. I haven't had a chance to try either yet but I'll let you know as soon as I do. Thanks again!

avatar image
0

Answer by operand · Jun 27, 2011 at 01:03 PM

I'm using the script you posted Meltdown (with javascript modifications) and the lower boundary works, but as the cylinder rotates back up to 0 it just keeps snapping to -100. So basically I can only rotate my dial left, then it keeps snapping back to the lower boundary value. The script looks like this.

     var currentRotation : float;
 
 function FixedUpdate(){
  
 currentRotation = rigidbody.transform.eulerAngles.z;
 Debug.Log(currentRotation);
 
   if(currentRotation < -100)
     rigidbody.transform.eulerAngles.z = -100;
   else if(currentRotation > 100)
     rigidbody.transform.eulerAngles.z = 100; 
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Have an object bounce off colliders instead of drift 2 Answers

How to make a RigidBody not go into ground when tilted foward? 2 Answers

Rotating object using touch controls mobile 0 Answers

How to rotate gameobject and rigidbody? 2 Answers

Lookat Direction by AddTorque? 0 Answers


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