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
1
Question by adrianks47 · Feb 13, 2013 at 11:57 PM · javascriptfpsoptimizationeulerangleszombie

Why changing eulerangles causes so much FPS drop?

I figured out that this part of the code was causing a lot of FPS drop.

 transform.eulerAngles.x = 0;
 transform.eulerAngles.z = 0;

It looks so harmless. Why does that happen?

Comment
Add comment · Show 4
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 Benproductions1 · Feb 14, 2013 at 10:46 PM 0
Share

Are you sure that this is causing the fps drop? Quaternions might be faster, try that?

avatar image Philipp · Feb 14, 2013 at 11:05 PM 0
Share

It might be the transform access, if you're actually doing this hundreds or thousands of times per frame. Try caching the Transform in a member variable, ins$$anonymous$$d of looking it up every time you need it.

Also, don't set the euler angles' x and z components separately. Under the hood, Unity will transform euler angles to quaternions, and it will have to do the required calculations twice, if you set them this way.

Both of these things should really only have a noticeable impact if you're manipulating a large amount of objects at once (but then the impact can be surprisingly large). Is that the case?

avatar image adrianks47 · Feb 15, 2013 at 02:37 AM 0
Share

Luckely i dont need those lines of code anymore. I did that because i set the rigidbody to freeze rotation but the eulerangles was slightly changing on the inspector

avatar image chanfort · Nov 17, 2015 at 02:34 AM 0
Share

There is indeed various functions used from $$anonymous$$athf running slower than from System.$$anonymous$$ath. Here I made a replacement example for Vector3.Angle() and Vector2.Angle():

 public static float Angle2d(Vector2 a, Vector2 b){
     double ax = (double)a.x;
     double ay = (double)a.y;
     
     double bx = (double)b.x;
     double by = (double)b.y;
     
     double dotd = ax*bx + ay*by;
     
     double a$$anonymous$$ag = System.$$anonymous$$ath.Sqrt(ax*ax + ay*ay);
     double b$$anonymous$$ag = System.$$anonymous$$ath.Sqrt(bx*bx + by*by);
     
     double aCos = System.$$anonymous$$ath.Acos(dotd / (a$$anonymous$$ag * b$$anonymous$$ag));
     
     return (float)(aCos*180/3.14159265359);
     
 }

 public static float Angle3d(Vector3 a, Vector3 b){
     double ax = (double)a.x;
     double ay = (double)a.y;
     double az = (double)a.z;
     
     double bx = (double)b.x;
     double by = (double)b.y;
     double bz = (double)b.z;
     
     double dotd = ax*bx + ay*by + az*bz;
     
     double a$$anonymous$$ag = System.$$anonymous$$ath.Sqrt(ax*ax + ay*ay + az*az);
     double b$$anonymous$$ag = System.$$anonymous$$ath.Sqrt(bx*bx + by*by + bz*bz);
     
     double aCos = System.$$anonymous$$ath.Acos(dotd / (a$$anonymous$$ag * b$$anonymous$$ag));
     
     return (float)(aCos*180/3.14159265359);
     
 }

performance is very clear when running many thousands calculations on every Update(). I am looking forward to find how eulerAngles is really working (i.e. what $$anonymous$$ath functions can be called) and what would be manual way to replace it.

0 Replies

· Add your reply
  • Sort: 

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

Why CPU waits for GPU when there is not much work on GPU? 0 Answers

I have some code for the zombie AI but.... 2 Answers

My gun wont fire ! 1 Answer

Any good FPS zombie game names? 1 Answer

UnityEngine has no appropriate version problem 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