- Home /
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!
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?
yes, that's what i want... but i already did it, I want to optimize it.
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.
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 :)
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.