Posted: Thu May 12, 2022 9:03 pm Post subject: Re: math.clamp
Frouk wrote:
function that compares value with min and max and replace it with min or max and return the value
I don't think this is the right explanation for math.clamp, at least you try to give a more specific explanation to the readers.
What is math.clamp in Lua?. Is it useful or no and how it’s working?.
Code:
math.clamp(x, min, max) clamps a number (x) between min and max. If it’s greater than max, it’ll return max. If it’s lower than min, it’ll return min. Otherwise, it’ll return x. You could’ve just checked the wiki, though.
“It takes 3 values. X, min and max. If X is in the range between min and max it returns X. If X is lower than min it returns min and if X is higher than max it returns max.
This can be useful for tons of applications, but a good example would be constraining rotation on an axis. If you want a player to control the rotation of a brick on the Y axis but only in a 90 degree window you could clamp it’s total rotation.”
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum