From dcfa657f649a4b64942f157b359f40720a994f7c Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Apr 2019 22:04:18 +0200 Subject: [PATCH] utils: add a simple function to substract a variable to another to zero --- gamecore/utils/math.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gamecore/utils/math.lua b/gamecore/utils/math.lua index 4168c6b..1c29373 100644 --- a/gamecore/utils/math.lua +++ b/gamecore/utils/math.lua @@ -40,6 +40,16 @@ function Math.round(num) return math.floor(num + 0.5) end +function Math.toZero(num, sub) + local sub = math.floor(sub) + + if math.abs(num) < sub then + return 0 + else + return num - (sub * Math.sign(num)) + end +end + -- VECTOR/DIRECTION functions -- Easy-to-use function to handle point and motion