• 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 $$anonymous$$ · Dec 13, 2016 at 06:08 AM · rotation axissimulation

object rotation simulation based on other two objects rotation. like changing frequency(anolog) in radio with two knobs

Here is the situation , i have two knobs and one frequency indicator. the rotation of indicator should be based on the rotation angle(value of rotation) of both the knobs . (say knobs are rotating in Y-axis, and indicator should rotate on X-axis ) alt text

capture.png (34.1 kB)
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
0

Answer by Potatobob · Dec 13, 2016 at 06:58 AM

Hi there !

First of I think if we follow the capture you attached that all the rotations can be done on the same axis. Unless your objects have a different rotation to start with.

Now in the case you want to set the INDICATOR rotation accordingly to one of the knob , and you want it to follow perfectly I would begin by placing them both at the same angle example:(Indicator vector3(0,0,90) and the knob vector3(0,90,0))

The calculation I would do afterwards would be to find the difference between both angles (note since you only rotate on one axis (different axis on the two objects but still a single value) we can use a float for this)

 float offset = knob.transform.eulerAngles.y - indicator.transform.eulerAngles.z;

After this we simply have to add make the rotation accordingly to the offset we have between both angles like so :

 Indicator.transform.Rotate(0,0,offset);

Now lets say that you want your 2 knobs to affect together the indicator YOU will have to come up with the maths you want for it to work. Here is a simple example: add the rotation of the two knobs together and divide by 2 in order to get the offset this time Like so :

 float offset = (knob1.transform.eulerAngles.y + knob2.transform.eulerAngles.y) / 2 - indicator.transform.eulerAngles.z;

Here is a second example of how you could calculate this, you could use the offset float and simply multiply it by a smaller number then 1 but bigger then 0. It will basically act as a divider for your number. Like so:

 float offset = (knob1.transform.eulerAngles.y + knob2.transform.eulerAngles.y) / 2 - indicator.transform.eulerAngles.z;
 offset *= 0.5f ; <--- this is what I would do personally.

I would finish by adding limitations on the rotation of the knobs and indicator. The main reason is that the angle could be below 0 or over it with by example: The angle 270 and -90 being the same angle..

So MY final code would probably look like this:

 //first set the variable names so we save on processing
 Quaternion knob1Rot = knob1.transform.eulerAngles;
 Quaternion knob2Rot = knob2.transform.eulerAngles;
 Quaternion indicatorRot = indicator.transform.eulerAngles;
 
 //if the angle Y is less then 0 , add the reverse of the missing angle to get 0 (ahhh maths)..
 if (knob1Rot.y < 0) {knob1Rot.Rotate(0,-knob1Rot.y,0) }
 if (knob2Rot.y < 0) {knob2Rot.Rotate(0,-knob2Rot.y,0) }
 
 float maxAngle = 180; //I don't want MY knobs to rotate more then 180 degrees
 if (knob1Rot.y > maxAngle ) {knob1Rot.Rotate(0,maxAngle -knob1Rot.y,0) }
 if (knob2Rot.y > maxAngle ) {knob2Rot.Rotate(0,maxAngle -knob2Rot.y,0) }
 
 //now that the knobs are not outside of their limits I would set the rotation of the indicator:
 float offset = (knob1Rot.y + knob2Rot.y) / 2 - indicatorRot.z;
 offset *= 0.5f ;
 Indicator.transform.Rotate(0,0,offset);
 
 /*and If you really have processing power to loose but want to MAKE SURE that the rotation of the indicator is not off limit , just do the same as the knobs limitation :*/
 if (indicatorRot.z < 0) {indicatorRot.Rotate(0,0,-indicatorRot.z) }
 if (indicatorRot.z > maxAngle ) {indicatorRot.Rotate(0,0,maxAngle -indicatorRot.z) }

At this point you can really decide how the knobs affect the indicator by yourself !

I hope this will be usefull , maybe not all the information there will be good for you but I hope at least a part of it is !

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotate Character Controller around y -axis 0 Answers

Rotation certain number of degrees 1 Answer

How do you make a Tps cam with RotateAround around the X and Y axis without rotating on the Z axis? 1 Answer

Rotation on Y axis when position is not horizontal,Rotation on Y axis when player not horizontal 0 Answers

Light gun simulation 2 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