Algorithm Help

Hello. I am having troubles creating a algorithm that fits my needs.

So I have a minimum value, a maximum value, and a control value.

The control value can go below the minimum value and above the maximum value.

I need it so the output value is 0.0 when Control <= Minimum, and 1.0f when Control >= Maximum.

Mathf.Clamp(control, min, max)

Alternatively, if you need to include min/max, you have (similar to the suggested if/else block):

Mathf.Max(min, Mathf.Min(max, control)) 

Okay I figured it out. The Mathf.Clamp helps a little.

(Mathf.Clamp(control, min, max) - min) / (max - min);

Hello! I know this is a very old thread, but I have come across it because I have a similar issue to the one OP has. For context, I am using the distance between two position vectors for the control variable, a min of 1, and a max of 20. The goal is that the closer I get to my target position, the output value of the algorithm increases from 0 to 1. However, with the solution OP has suggested I do the exact opposite, decreasing from 1 to 0 the closer I get. Any help would be really appreciated, but I’ll continue to toy with this for a little while too.