• 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
3
Question by dean_0707 · Jun 07, 2012 at 11:49 AM · rotateaxiscontinuous

Continuously Rotating Script?

Hi, I just needed the code to make a GameObject continuously rotate around on it's y axis throughout the whole game (preferably every 5-6 seconds is will reach 360 Degrees and start again if you know what I mean). Thanks, Dean.

Comment
Add comment · Show 1
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 SallarQ · Jul 21, 2017 at 04:02 PM 0
Share

i'm also looking for this, but i also want to move the objects from left to right, i'm using three rocks and i want it them to spin and move from left to right, i hope you can understand, i can't explain more b/c my English is so bad, Thank you in advance.

2 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by Bunny83 · Jun 07, 2012 at 11:51 AM

That's really easy:

 var rotationsPerMinute : float = 10.0;
 function Update()
 {
     transform.Rotate(0,6.0*rotationsPerMinute*Time.deltaTime,0);
 }
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 idiot333 · Feb 20, 2015 at 07:20 PM 0
Share

what if we do not want to put it in the update function? I mean, i just wanna call the function once and it should continuously rotate it.

avatar image Ravenholmn idiot333 · Jun 28 at 01:15 PM 0
Share

@idiot333 if you dont want to use a rigibody you can use a self looping coroutine instead.

     float rotationsPerMinute = 10.0;
 
     Start()
     {
         OpenCoroutine();
     }
 
     private void StartRotationCoroutine()
     {
         if (canRotate)
         {
             StartCoroutine(InstantiateParentCoroutine(spawnDuration));
         }
     }
 
     private IEnumerator InstantiateParentCoroutine(float delayTime)
     {
         transformToRotate.Rotate(0, 6.0 * rotationsPerMinute * Time.deltaTime, 0);
         yield return new WaitForEndOfFrame();
         StartRotationCoroutine();
     }
 
 
 //you can add these to have the ability to stop and reenable this infinite loop
     public void OpenCoroutine()
     {
         canRotate = true;
         StartRotationCoroutine();
     }
 
     public void CloseCoroutine()
     {
         canSpawn = false;
     }
avatar image HappyLDE · Feb 20, 2015 at 07:54 PM 1
Share

@idiot333 you can then in the Start() function set the torque to a rigidbody without it having angular drag: rigidbody2D.AddTorque(20);

avatar image
1

Answer by dean_0707 · Jun 07, 2012 at 04:35 PM

Yes, This was exactly what I was looking for, I'm a beginner with Unity so it all seems pretty hard, thanks!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with transform.Rotate 1 Answer

Rotating Cuboid Around Pivot 2 Answers

Creating an axes representation on the screen? 0 Answers

X position relative to..... world? 1 Answer

Lock Z Rotation. Character Controller. 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