- Home /

# 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?

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

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?

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

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.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

fps drop even after optimization 3 Answers

How to let my gun shoot ?? 0 Answers

Script not working at ALL 0 Answers

Enemy AI Range Detection 3 Answers

Making a GetComponent array 1 Answer