clamp moves value to maximum when minimum is reached
//The problem is when the object is rotated enough that it becomes messy.
//This code fixes the clamp...
float fixedClamp(float value, float min, float max)
{
    if (value < 90 || value > 270)
    {
        if (value > 180) value -= 360;
        if (max > 180) max -= 360;
        if (min > 180) min -= 360;
    }
    value = Mathf.Clamp(value, min, max);
    if (value < 0) value += 360;
    return value;
}
