From d143d492a1ed4adfb21f57d0f9799e9062dd691a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 27 May 2017 00:27:56 +0200 Subject: [PATCH] Check for arrow collision every tick --- mods/ITEMS/mcl_throwing/arrow.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_throwing/arrow.lua b/mods/ITEMS/mcl_throwing/arrow.lua index a1f19c146..bfa2d144f 100644 --- a/mods/ITEMS/mcl_throwing/arrow.lua +++ b/mods/ITEMS/mcl_throwing/arrow.lua @@ -40,7 +40,6 @@ local THROWING_ARROW_ENTITY={ textures = {"mcl_throwing:arrow_box"}, collisionbox = {0,0,0,0,0,0}, - _timer=0, _lastpos={}, _startpos=nil, _damage=1, -- Damage on impact @@ -48,11 +47,11 @@ local THROWING_ARROW_ENTITY={ } THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self._timer=self._timer+dtime local pos = self.object:getpos() local node = minetest.get_node(pos) - if self._timer>0.2 then + -- Check for object collision. Done every tick (hopefully this is not too stressing) + do local objs = minetest.get_objects_inside_radius(pos, 2) local closest_object local closest_distance @@ -118,6 +117,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) end end + -- Check for node collision if self._lastpos.x~=nil then local def = minetest.registered_nodes[node.name] if (def and def.walkable) or not def then @@ -127,6 +127,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) self.object:remove() end end + + -- Update internal variable self._lastpos={x=pos.x, y=pos.y, z=pos.z} end