I need to clamp an angle by -90 +90, but the angle goes from 0 to 360.

I use “transform.rotation.eulerAngles” to get my angles and the classic ClampAngle function to clamp, but it can’t work because the correct angle would go from 270 to 0 and from 0 to 90

how to solve this?

(also why sometimes the transform.rotation.eulerAngles returns me an angle that is 0-360 and sometimes -360+360? )

thx!

Add 90, clamp to 0 - 180, subtract 90.

Depending on what you are trying to do, this might not be correct, but if you are say trying to let someone turn a wheel until it gets to -90 or 90

```
float angleX = transform.rotation.eulerAngles.x;
if(angleX > 180 angleX < 270)
angleX = 270;
else if (angleX < 180 angleX > 90)
angleX = 90;
```

2 Likes

I always do it via helper Vector3. just clamp the helper vector and then set eulerangle=helper…a vector3 doesnt have that angle restrictions