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 rajat · Mar 20, 2013 at 11:54 AM · transformanimation script

Constantly rotate a gameobject around y axis.

I want to keep rotating a gameobject throughout the scene, Currently what code i am using is..

   void Update () {
     //rotate the current item
     items[currentItem].transform.Rotate(0,1,0);
     }

However, I think this is not efficient as update gets called in between the object is rotating so there is a huge buffer of rotation building up and the object keeps on rotating even when the gameobject (items[currentItem]) changes. How can i inexpensively keep rotating a object and make it stop as soon as it is not getting any more rotation commands.

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

Answer by Fattie · Mar 20, 2013 at 12:49 PM

  1. this is perfectly, flawlessly, amazingly efficient

  2. note that it is extremely unlikely you want to rotate it by "1" every frame (frames happen up to 100s of times per second)

  3. it is very likely you want to do something like .Rotate( 0, Time.deltaTime, 0)

  4. you can find endless examples on here about the details of this, eg

http://answers.unity3d.com/questions/52790/constant-rotation-to-an-object.html

search in google on "answers.unity3d.com Rotation Time.deltaTime" to find literally 100s of such answers.

more tricky ...

http://answers.unity3d.com/questions/14527/rotate-90-over-time-on-mousedown.html

  1. there is no "buffer" whatsoever

  2. when you change "currentItem", it will instantly stop rotating the previous "currentItem" and begin rotating the new "currentItem". If it does not: you have made a mistake somewhere else. To solve that problem, add a debug line, Debug.Log .. etc

  3. regarding the question of "how to do this only when a button is being held down"

Essentilally, you add code like this:

 function Update()
     {
     if the button is being held down then
          items[currentItem].transform.Rotate(0,1,0);
     }

regarding how to detect if a button is being held down, search on here for 1000s of answers

or glance at the doco

http://docs.unity3d.com/Documentation/ScriptReference/Input.html

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButton.html

Hope it helps !!!

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 rajat · Mar 20, 2013 at 01:01 PM 0
Share

Hi, Thanks for the detailed response. I am not using mouse for interaction, i am using kinect and detecting hand movement and current item changes when the hand is over other item. but the previous item keeps on rotating .

avatar image rajat · Mar 20, 2013 at 01:11 PM 0
Share

(1) I applied the Time.deltaTime now, seems to be working fine now. Thanks :).

(2) Ok, i will look for the problem, no need for the all caps rage .

(3) The mentioned code as such has nothing to do with the kinect, i meant to say that using mouseclick is not a option.

Thanks for all the help.

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

Double Tap Not Working 1 Answer

Transform [] = all children of this game object ? (Spawnpoints) 3 Answers

Send array of transforms via RPC. [C#] 1 Answer

How to set a Transform variable with code (C#) 3 Answers

Perpendicular forward :-) 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