Convert 0-360 to limit object rotation

Hi,

I’m trying to make a rotation wheel, and basically what I want to do is to limit the wheel rotation say 90 degrees to right and 270 to left(like a steering wheel).First, I convert values from 0 - 360 if(angle<0){angle+=360} //this gives me the values 0-360, which is pretty good.

My math looks like this:
if(angle>90) {angle = 90} //this part works perfect, however if i want to steer left:
if(angle<270) {angle = 270} // here is the confusion because, say 265<270 is true, but 265>90 is also true.

If anyone could explain how to convert the values from 1 to 180(right part) and from -1 to -180(left part), then I guess the solution would be simplier.

I used Math.Clamp(angle, -100, 100), but didn’t work.

Thanks.

Maybe try to use -90 instead of 270.

Or you can do other simple method:

Quaternion rotation;
rotation.eulerAngles = Vector3.zero;

void Update()
{
    rotation += rotationChange; //rotationChange - Quaternion of how much degrees you want to add at a frame;
    gameObject.transform.rotation = rotation;
    if (rotation.eulerAngles.z > 90.0f) gameObject.transform.rotation.eulerAngles = Vector3(rotation.x, rotation.y, 90.0f);
    else if (rotation.eulerAngles.z < -90.0f) gameObject.transform.rotation.eulerAngles = Vector3(rotation.x, rotation.y, -90.0f);
}

This may be one of the simpliest methods, try if it works.

Solved!

For anyone who need this,

First, get the values 0-360 if(angle< 0){angle+=360} // 0-360
Second, get right rotation part values (0 to 180) and left part (0 to -180) with this:
if(angle>180){angle-=360} // 0-180 , -180-0

Now, we can set the rotation limit like this:
if(angle>120) {angle=120} //right limit
if(angle<-120) {angle=-120} //left limit