Have you tried using clamp?
clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.
Develop games in your browser. Powerful, performant & highly capable.
Member since 25 Dec, 2014