1
0
Fork 0

Check for arrow collision every tick

objects
Wuzzy 2017-05-27 00:27:56 +02:00
parent d7a42bd831
commit d143d492a1
1 changed files with 5 additions and 3 deletions

View File

@ -40,7 +40,6 @@ local THROWING_ARROW_ENTITY={
textures = {"mcl_throwing:arrow_box"}, textures = {"mcl_throwing:arrow_box"},
collisionbox = {0,0,0,0,0,0}, collisionbox = {0,0,0,0,0,0},
_timer=0,
_lastpos={}, _lastpos={},
_startpos=nil, _startpos=nil,
_damage=1, -- Damage on impact _damage=1, -- Damage on impact
@ -48,11 +47,11 @@ local THROWING_ARROW_ENTITY={
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self._timer=self._timer+dtime
local pos = self.object:getpos() local pos = self.object:getpos()
local node = minetest.get_node(pos) 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 objs = minetest.get_objects_inside_radius(pos, 2)
local closest_object local closest_object
local closest_distance local closest_distance
@ -118,6 +117,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
end end
-- Check for node collision
if self._lastpos.x~=nil then if self._lastpos.x~=nil then
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if (def and def.walkable) or not def then if (def and def.walkable) or not def then
@ -127,6 +127,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.object:remove() self.object:remove()
end end
end end
-- Update internal variable
self._lastpos={x=pos.x, y=pos.y, z=pos.z} self._lastpos={x=pos.x, y=pos.y, z=pos.z}
end end