From 84f6c2f3c98e5fa53540052587a3e253c0e56592 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Thu, 6 May 2021 18:01:33 -0700 Subject: [PATCH] Hack: check that coordinates are numbers before setting new velocity --- init.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 2a79ab4..21dab1e 100644 --- a/init.lua +++ b/init.lua @@ -101,6 +101,11 @@ def.on_activate = function(self,staticdata) end end + +local function isnan(n) + return tostring(n) == tostring((-1)^.5) +end + def.on_step = function(self, dtime) if self.knockback then return @@ -267,7 +272,19 @@ def.on_step = function(self, dtime) self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)} local direction = self.direction - self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5}) + + -- FIXME: hack + local can_set = true + for _, c in ipairs({direction.x*2.5, direction.z*2.5}) do + if isnan(c) then + can_set = false + break + end + end + + if can_set then + self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5}) + end -- Jump if self.jump_timer > 0.2 then