New Lua functions, math.sign and math.clamp

In the future, could we possibly have a function called math.movetowards(current, target, maxDelta)?
It would behave like this:

local function moveTowards(current, target, maxDelta)
	if current < target then
		return math.min(target,current + maxDelta)
	elseif current > target then
		return math.max(target,current - maxDelta)
	else
		return target
	end
end

I use this function a lot in my code, mostly in heartbeat threads for doing visual transitions between states.
It would be handy to have something like it built-in.

7 Likes