Map Range Clamped
Converts a value that is in a range of values to the corresponding value in another range of values. The end result will always be in the range of output values even if the original value is outside the range of input values.
Input
- Value: Original value to be converted.
- In Range A: Minimum value of the input value range.
- In Range B: Maximum value of the input value range.
- Out Range A: Minimum value of the output value range.
- Out Range B: Maximum value of the output value range.
Output
- Return Value: Converted value to the output value range.
Example Usage:
In the example below, a float variable is being used to represent the rotation of an object. This variable can contain values between 0.0 and 1.0. A function was created to convert the value of this variable to the equivalent value in degrees. If the value is 0.0 then the equivalent in degrees is 0. If it is 1.0 the equivalent in degrees is 360. If the value is 0.5 then the result will be 180 degrees.
Click to enlarge |
In another example, the "Get Percentage Ammo" function converts the current amount of the player's ammo into a percentage so it is displayed on the screen. The calculation is based on variables that hold the maximum ammunition that the player can have and the current amount of ammunition.
Click to enlarge |
There is a variation of this function called "Map Range Unclamped", the only difference being that the end result is not limited to the range of output values.