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 ThiagoTejo · Dec 12, 2013 at 01:28 AM · rotationoptimizationcpu

Wich one of these is Less CPU Consuming?

Hello guys, i've made a code to get the values for the y and w rotations of the camera, to align my character to those, but i want to know, wich one of those methods will give me less lag.

Option 1

 rotationR = (mainCamera.rotation * Quaternion.LookRotation(direction, Vector3.up));
 
 myTransform.rotation = Quaternion.Slerp(myTransform.rotation,Quaternion(0,rotationR.y,0,rotationR.w), 10 * Time.deltaTime);

With this one, i get the entire rotation from the camera and put it in the rotationR variable. and then, i set my character rotation to align with only the y and w of rotationR.

Option 2

 rotationR = (mainCamera.rotation * Quaternion.LookRotation(direction, Vector3.up));
 rotationR.x = 0;
 rotationR.y = 0;
                    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,rotationR, 10 * Time.deltaTime);

In this one, I "manually" set the x and y values of rotationR to zero.

I'm using these on update function, so, that's why i'm trying to consume less CPU. Looking at it, there's no apparent difference, but i want to know, techinically, which one consume less? There's a simpler way to do this? thanks in advance!

Comment
Add comment · Show 5
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 robertbu · Dec 12, 2013 at 01:49 AM 0
Share

I obviously missed the mainCamera.rotation part. So what are you trying to do here:

 mainCamera.rotation * Quaternion.LookRotation(direction, Vector3.up)

You want the character face some direction relative to the camera rotation?

avatar image ThiagoTejo · Dec 12, 2013 at 01:52 AM 0
Share

yes, that's what i want... but i already did it, I want to optimize it.

avatar image ikelaiah · Dec 12, 2013 at 05:38 AM 1
Share

If there is a problem then we can find ways to optimise it. What problem are you solving that you want to $$anonymous$$imise CPU usage? Below 15 fps? If the answer is none, you may consider this link on premature optimisation.

avatar image ThiagoTejo · Dec 12, 2013 at 02:25 PM 0
Share

Actually, my game runs fine either way, I just wanted the less CPU consu$$anonymous$$g way, even if the difference is $$anonymous$$imal. I've never had heard this term before, "premature optimisation", and that seems to be what I was doing... I still doesn't think that doing it is all that bad, if it doesnt take too much time or make the code unclear, but i'll try to be less excessive next time, thanks :)

avatar image ikelaiah · Dec 13, 2013 at 02:29 AM 0
Share

@ThiagoTejo

I agree, it is not all bad, depending on your circumstance. For example, you're building a web application, and let's assume you know FOR CERTAIN, that your user would have access to 1$$anonymous$$bps connection only. Definitely, at the beginning of your project you want to optimise user experience by $$anonymous$$imising bandwidth as much as possible. Because, you can be certain (by doing test), sending large data over network is not desireable, thus you can begin by giving yourself a constrains, e.g., downloadble media must be counted in bytes, not kilo bytes, use acceptable lower quality music, etc. Unless matrix rotation algorithm is a real performance issue, you may leave it as it is.

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

17 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

Related Questions

How to make common material for CPU optimization? 1 Answer

Optimized Scripting - Variables 1 Answer

VideoPlayer is choppy while preparing and before playing. 0 Answers

Rotating objects: Script vs. Animation efficiency 5 Answers

Why is the CPU usage so high? 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