Tnt: Avoid divide-by-zero errors in calc_velocity()
[oweals/minetest_game.git] / mods / tnt / init.lua
index 2f0ffdc413ec7d6034c9c367c358f9091aad38b0..9fd97f4926b7414d41c5bee3e7ede6f0b0f5f487 100644 (file)
@@ -110,6 +110,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)