Answers for "clamp moves value to maximum when minimum is reached"

C#
8

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;
}
Posted by: Guest on October-04-2021

Code answers related to "clamp moves value to maximum when minimum is reached"

C# Answers by Framework

Browse Popular Code Answers by Language