Tnt: Avoid divide-by-zero errors in calc_velocity() 0.4.14
authorparamat <mat.gregory@virginmedia.com>
Sun, 8 May 2016 21:26:18 +0000 (22:26 +0100)
committerparamat <mat.gregory@virginmedia.com>
Sun, 8 May 2016 21:53:16 +0000 (22:53 +0100)
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)