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
1
Question by iamhim · Jan 12, 2013 at 07:42 PM · guirotatelookatslerprotatetowards

Rotate slowly to target position?

I have this set of code which doesn't work

 if (GUI.Button(new Rect(Screen.width * 0.5f, Screen.height * 0.07f, Screen.width * 0.1f, Screen.height * 0.05f), "Rotate")){
         
         Quaternion neededRotation = Quaternion.LookRotation((GameObject.FindGameObjectWithTag("cube1").gameObject.transform.position - transform.position));    
         Quaternion.RotateTowards(transform.rotation, neededRotation, Time.deltaTime * 10f);        
             
         }

is there any other way to rotate slowly towards the gameobject? 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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Lovrenc · Jan 12, 2013 at 08:02 PM

You need to run this line multiple times (eg. un Update) to get animation:

 Quaternion.RotateTowards(transform.rotation, neededRotation, Time.deltaTime * 10f);
Comment
Add comment · Show 3 · 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 iamhim · Jan 13, 2013 at 08:35 AM 0
Share

tried it on the update() function but it still doesn't work, i'm trying to rotate the main camera though, thanks for trying to help

avatar image Lovrenc · Jan 13, 2013 at 12:41 PM 0
Share

Post the code..

avatar image ShudderPig · Nov 28, 2018 at 01:20 PM 0
Share

nearly 6 years later and this was super helpful. I was using transform.rotation = Quaternion.LookRotation(moveDirection), and this caused immediate choppy turning. transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(moveDirection), turnspeed * Time.deltaTime); however gives a nice turn, looks much cleaner and wasn't to word heavy. thankyou

avatar image
3

Answer by vincefryer · Jan 21, 2013 at 12:44 AM

Quaternion.RotateTowards() uses the Quaternion base class to find a rotation, but doesn't affect any instance of the class. You need to assign the value it returns to something meaningful (like transform.rotation) in order to see any effect.

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
avatar image
2

Answer by IgorAherne · Oct 22, 2016 at 07:34 PM

transform.rotation = Quaternion.RotateTowards(transform.rotation, neededRotation, Time.deltaTime * 10f);

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

11 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

Related Questions

Move & Rotate Camera after OnMouseDown() 2 Answers

Rotating Game Object in Movement Direction on planet with Faux Gravity Unity 3D 2 Answers

Controlling the speed of Vector3.RotateTowards 0 Answers

Quaternion Slerp is making me mad 2 Answers

Rotation with RotateAround 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