From 7fde587dabc55b4a01d70d6d2e106324faf4879f Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 21 Dec 2020 19:48:37 +0100 Subject: [PATCH] Move box_box_collision to vector & fix it --- minetest.lua | 9 --------- vector.lua | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/minetest.lua b/minetest.lua index 93d878f..2cf101a 100644 --- a/minetest.lua +++ b/minetest.lua @@ -101,15 +101,6 @@ function check_player_privs(playername, privtable) return missing_privs, to_lose_privs end -function box_box_collision(a, b) - for i=1, 3 do - if a[i] < (b[i] + b[i+3]) or b[i] < (a[i] + a[i+3]) then - return false - end - end - return true -end - minetest.register_globalstep(function(dtime) for k, v in pairs(delta_times) do local v=dtime+v diff --git a/vector.lua b/vector.lua index c3c278a..23b43f2 100644 --- a/vector.lua +++ b/vector.lua @@ -76,4 +76,13 @@ end function clamp(v, min, max) return apply(apply(v, math.max, min), math.min, max) +end + +function box_box_collision(diff, box, other_box) + for index, diff in pairs(diff) do + if box[index] + diff > other_box[index + 3] or other_box[index] > box[index + 3] + diff then + return false + end + end + return true end \ No newline at end of file