Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by NohanG · Jan 13, 2016 at 12:54 PM · c#rotationobjectquaternionienumerator

How to rotate object back and forth from one rotation to another?

I figured I could use something like an IENumerator but I want the object to rotate back and forth from two set positions every x seconds. Thanks for any help

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
15

Answer by Segy · Apr 30, 2016 at 05:41 PM

I know this answer is too late for you, but hope this helps anyone else with the same problem in the future!

         public float speed = 2f;
         public float maxRotation = 45f;
     
         void Update()
         {
             transform.rotation = Quaternion.Euler(maxRotation * Mathf.Sin(Time.time * speed), 0f, 0f);
         }

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 splitter20 · May 28, 2016 at 05:52 AM 0
Share

Thanks for the reply! Even though it's an old post this helped me out a ton.

avatar image Nikowill1 · Feb 02, 2017 at 10:29 PM 0
Share

Thanks! But how can I change the start rotation angle?

avatar image unity_bfawXRcvR563OA · Jul 11, 2019 at 07:39 PM 0
Share

what about have it rotate a little slower every time it hits the end?

avatar image fibeesoft · Nov 06, 2019 at 07:21 PM 0
Share

Can't believe it, I searched for it for an hour with many complicated answers. This is just amazing. Thanks

avatar image NoteMEdown · Jun 23, 2021 at 08:58 PM 0
Share

I recommend changing transform.rotation to transform.localRotation, Allowing you to change the parent objects rotation, while keeping the same movement. I rarely recommend changing rotation directly.

avatar image
0

Answer by VoltzStudios · Dec 15, 2016 at 02:03 AM

The rotation thing doesn't rotate, it grows and shrinks the object.

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 colorpillar · Jan 18, 2017 at 05:06 PM 0
Share

Hello, this is because the example above applies rotation to the x Axis. It would be helpful to read up about rotational maths if you are not able to apply this to suit your needs. http://mathworld.wolfram.com/Rotation$$anonymous$$atrix.html That.. or ("I don't wanna be That guy but...) check the methods you intend to use before actually applying them in code..

avatar image King-Lube-III · Jan 27, 2019 at 10:44 AM 0
Share

To rotate a 2D-GameObject like a sprite you should rotate along the z-axis: Simply move the rotation-value from the first to the last position:

transform.rotation = Quaternion.Euler(0f, 0f, maxRotation $$anonymous$$athf.Sin(Time.time speed));

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

14 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

Related Questions

How to limit only one axis rotation? c# 1 Answer

Trying to get Player Character to look at the mouse pointer... which i have done, but would like to smooth the rotation. 1 Answer

How to use physics to make an object face a specific direction 0 Answers

Unity lookat at finger position 3D C# 0 Answers

Rotation Perpendicular to Line Segment 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