Skip to content
drewmccluskey edited this page Jan 14, 2019 · 1 revision

clamp

This function returns an input within the bounds of a specified range.

Syntax:

clamp(T val, T min, T max)
Argument Description
T val The input value to be kept within a range
T min The lowest range which it will clamp the input to
T max The highest range which it will clamp the input to

Returns: T

Description:

This function returns an input value within a specified range. It is used to keep a variable within a certain limit so it may not go above or below the range minimum or maximum.

Example:

var speed = clamp(speed, -3, 5); //keeps speed from going below or above the min and max range

This code will keep the variable speed between -3 and 5. If speed is above 5, it will clamp it back down to 5. If it is below -3, it will clamp it up to -3. If it is within the range of -3 and 5, it will leave it as is.

Back to number_functions

Clone this wiki locally