Skip to content

Commit

Permalink
Hack: check that coordinates are numbers before setting new velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 7, 2021
1 parent 6c46f8b commit 84f6c2f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 84f6c2f

Please sign in to comment.