Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 oxa89 · Oct 16, 2014 at 03:37 PM · rotationtransformpositionlerp

Move object while rotating another one

Hello. I am making something like old FM radio.

There is a wheel that can be rotated with mouse. Here is the code how I rotate it:

 mouseClickPos = Input.mousePosition;    
 Vector3 dir = mouseClickPos - Camera.main.WorldToScreenPoint(transform.position);
 angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
 angle-=90;
 angle = Mathf.Round(angle/6.0f)*6.0f;
 Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
 hand1.transform.rotation = Quaternion.RotateTowards(hand1.transform.rotation, q, 6);

Now there is an arrow that needs to be moved on y axis from -4 to 4 when wheel is rotated. The arrow starts in 4, and when wheel is rotated to the right, arrow needs to go towards -4 point. And when it reaches -4, it needs to go back to 4 while wheel is rotated in same direction as from beginning. If player starts to rotate wheel to the other side (left), the arrow needs to start moving to the other side from the side it was going until then. I did try something like this but it is not working:

 a1 = Mathf.Floor(oblaci.transform.localRotation.eulerAngles.z);
 if(arrow.transform.localPosition.y >= 4.0f)
 {
         arrowUp = !arrowUp;
 }
         else if(arrow.transform.localPosition.y <= -4f)
 {
     arrowUp = !arrowUp;
 }
 if(a1>a2)
 {
     if(arrowUp)
     {
                 arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
     }
     else
     {
         arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);                        
     }
 }
 else if(a1<a2)
 {
     if(arrowUp)
     {
         arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);
     }
     else
     {
         arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
     }
 }
 a2=a1;



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
Best Answer

Answer by bubzy · Oct 20, 2014 at 12:51 PM

like this ?

http://www.westwalescse.net/unity/radio/radio.html

http://www.westwalescse.net/unity/radio/ theres a zip file in here with the project.

Comment
Add comment · Show 4 · 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 oxa89 · Oct 20, 2014 at 01:53 PM 0
Share

Something like that. The problem is that when arrow reaches bottom while i am pulling mouse down, it should go up agan, not stand in bottom.

avatar image bubzy · Oct 20, 2014 at 04:46 PM 0
Share

http://www.westwalescse.net/unity/radio/radio.html try this again I've changed it, although it is odd behaviour for a radio imo... :D

avatar image oxa89 · Oct 22, 2014 at 11:57 AM 0
Share

I said I am making "something like radio" :) Thx for your work, but it's my mistake, I explained it poorly. When arrow reaches bottom, it should start moving towards the top, not just start from top again. Here is the picture how should it goalt text

While scrolling the wheel, arrow first goes towards bottom, then when it reaches bottom, it should start moving towards top (2.), and then again towards bottom (3.). But this example could be useful. Can I please get the zip?

untitled.png (4.1 kB)
avatar image bubzy · Oct 22, 2014 at 04:20 PM 0
Share

when I get home from work :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Move the rotated Game Object Forward 0 Answers

Align objects based on child objects 0 Answers

Ragdoll breaks and flys far into the air... 0 Answers

[solved] Get upward orientation of object and add scale value 1 Answer

How can I defer the recalculation of child transforms whilst modifying the parent transform? 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