From 504961a0a2af78ccb6d0011ebb022bcd83b3b72b Mon Sep 17 00:00:00 2001 From: paramat Date: Sun, 8 May 2016 22:26:18 +0100 Subject: [PATCH] cherry-pick from github.com/minetest/minetest_game> Tnt: Avoid divide-by-zero errors in calc_velocity() --- mods/tnt/init.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 1e5d5a50..18bd9263 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -104,6 +104,11 @@ end local function calc_velocity(pos1, pos2, old_vel, power) + -- Avoid errors caused by a vector of zero length + if vector.equals(pos1, pos2) then + return old_vel + end + local vel = vector.direction(pos1, pos2) vel = vector.normalize(vel) vel = vector.multiply(vel, power)