From b8145c5471aa6e691daea16c0e410567bbfe8c00 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Sun, 4 Dec 2016 14:04:54 +0100 Subject: [PATCH] [mobs] Avoid server crash with nan vector values --- mods/mobs/api.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index d87b1845..212998fb 100755 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -476,6 +476,15 @@ do_jump = function(self) end function calc_velocity(pos1, pos2, old_vel, power) --MFF we use this function + -- If the two positions are equal the vector will contain nan and crash the game + if (pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z) then + return { + x = 0, + y = 0, + z = 0 + } + end + local vel = vector.direction(pos1, pos2) vel = vector.normalize(vel) vel = vector.multiply(vel, power)