From 80739518226739ac59361092753358a74f8b7bc8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 2 May 2019 16:18:12 +0200 Subject: [PATCH] utils/math: add a function to return a value somewhere between two numbers --- gamecore/utils/math.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gamecore/utils/math.lua b/gamecore/utils/math.lua index 1c29373..fea382b 100644 --- a/gamecore/utils/math.lua +++ b/gamecore/utils/math.lua @@ -50,6 +50,12 @@ function Math.toZero(num, sub) end end +function Math.between(num, value1, value2) + local min = math.min(value1, value2) + local max = math.max(value1, value2) + return math.min(math.max(num, min), max) +end + -- VECTOR/DIRECTION functions -- Easy-to-use function to handle point and motion