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 /
  • Help Room /
avatar image
0
Question by zigglr · Jan 30, 2016 at 04:13 AM · c#unity 5rotation

How to reduce the speed of rotation?

I have a circle sprite which is constantly rotating, however it rotates way to fast. I have tried increasing the 'WaitForSeconds' but anything above 0.01 gives a choppy movement. Anyone know how to do this? Thanks

 IEnumerator rotate ()
 {
     transform.rotation = Quaternion.Euler(0f, 0f, -4f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -14f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -24);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -34f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -44f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -54f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -64f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -74f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -84f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -94f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -104f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -114f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -124f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -134f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -144f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -154f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -164f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -174f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -184f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -194f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -204f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -214f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -224f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -234f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -244f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -254f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -264f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -274f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -284f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -294f);
     yield return new WaitForSeconds(0.03f);
     transform.rotation = Quaternion.Euler(0f, 0f, -304f);
     yield return new WaitForSeconds(0.03f);
     transform.rotation = Quaternion.Euler(0f, 0f, -314f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -324f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -334f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -344f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -354f);
     yield return new WaitForSeconds(0.01f);
     transform.rotation = Quaternion.Euler(0f, 0f, -364f);
     yield return new WaitForSeconds(0.01f);
     StartCoroutine("rotate");





 }
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
0

Answer by Eno-Khaon · Jan 30, 2016 at 04:35 AM

Let's condense this a little bit, shall we?

 IEnumerator rotate ()
  {
      while(true) // Keeps it going, use yield statements to avoid infinite loop
      {
          transform.rotation *= Quaternion.AngleAxis(degreesPerSecond * Time.deltaTime, Vector3.forward);
          yield return null;
      }
  }

For reference, I use "yield return null" for reasons described in another answer (This one). The rotation rate is calculated based on degrees rotated per second, which can be hard-coded or given a variable (as desired), and the rotation axis should be in world coordinates rather than local coordinates to maintain proper order of operations in Quaternion multiplication.

Comment
Add comment · Show 1 · 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 Owen-Reynolds · Jan 30, 2016 at 03:35 PM 0
Share

Yes, use a loop. The thing is, if you (the original poster) didn't already know that, get any book about computer program$$anonymous$$g (not Unity -- just a basic book.) It will have a bunch of easy stuff in it, like loops, which you didn't know.

This answer is rewriting your code a lot. It's a more normal way to slowly spin. But you could also make a loop that keeps the same 2 lines you wrote.

avatar image
0

Answer by DroidifyDevs · Jan 30, 2016 at 03:53 PM

OK. If you have a script that is THAT REPETITIVE, YOU'RE DOING SOMETHING WRONG.

You're getting choppy results because you are spinning it only 10 degrees at a time. So, you're doing this: -4, -14, -24, -34, -44, -54 etc... meaning that it is 10 times choppier than it would be if you used a loop.

So, to save yourself the PITA of copying code 360 times, learn how to use loops. @Eno Khaon did a good job with his answer, and I clarified why it is so choppy.

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

69 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 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 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 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 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

Rotation script issue? 2 Answers

Simple Rotate Script won't work! 2 Answers

Unity 2D rotation not smooth? 0 Answers

Unity - Problems with Bone Rotations within constraints 0 Answers

how do i rotate an object? C# 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