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 radove · Mar 01, 2016 at 12:59 PM · rotationtransformupdatefixedupdatelocaleulerangles

Optimizations: Should I use Update or FixedUpdate? Could you help me optimize rotations?

Hello, I have a lot of MoveTowards and "rotation" type code for my bad guys that are spawned. They rotate (they are balls) and they also MoveTowards a location. How can I optimize this code to run more efficiently? Please also let me know whether MoveTowards is supposed to be in Update() or FixedUpdate... I got confused on where it should be... same with rotation of the object.

This is currently in Update(). Should I be caching the transform or does it matter?

     float currentRotation = this.gameObject.transform.localEulerAngles.z;
     float newRotation = currentRotation + rotationSpeed;
     this.gameObject.transform.localEulerAngles = new Vector3(0f,0f,newRotation);

     destination = new Vector2 (randomPositionXStar, randomPositionYStar);
     this.transform.position = Vector2.MoveTowards (this.transform.position, destination, speed * Time.deltaTime);
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

Answer by Salocin19 · Mar 01, 2016 at 04:02 PM

In general, it is recommended to put physics related code (i.e. rotation / move-towards) in fixed update.

The Update() function runs at every frame of the game, whereas FixedUpdate() runs at a fixed rate independent of the framerate.

That being said, you probably don't want your physics to fluctuate if there are spikes of lag, or framerate differences, etc. So, the way to go is most likely FixedUpdate() in your case. In general, it is recommended to put physics related code (i.e. rotation / move-towards) in fixed update.

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 radove · Mar 04, 2016 at 02:04 AM 0
Share

Thanks for the feedback!!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Apply a rotation AND a torque at the same time ? 1 Answer

Transform.translate -> Update or FixedUpdate 1 Answer

Need help with my code 0 Answers

3 Axis Camera Rotation 0 Answers

Help with creating rotational mapping 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