Add Raytracing arrows
parent
ad486a56fd
commit
e1feec9a30
|
@ -188,7 +188,8 @@ function ARROW_ENTITY.on_step(self, dtime)
|
||||||
-- The radius of 3 is fairly liberal, but anything lower than than will cause
|
-- The radius of 3 is fairly liberal, but anything lower than than will cause
|
||||||
-- arrow to hilariously go through mobs often.
|
-- arrow to hilariously go through mobs often.
|
||||||
-- TODO: Implement an ACTUAL collision detection (engine support needed).
|
-- TODO: Implement an ACTUAL collision detection (engine support needed).
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 1.5)
|
|
||||||
|
|
||||||
local closest_object
|
local closest_object
|
||||||
local closest_distance
|
local closest_distance
|
||||||
|
|
||||||
|
@ -196,32 +197,26 @@ function ARROW_ENTITY.on_step(self, dtime)
|
||||||
self._deflection_cooloff = self._deflection_cooloff - dtime
|
self._deflection_cooloff = self._deflection_cooloff - dtime
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate through all objects and remember the closest attackable object
|
local arrow_dir = vector.rotate(vector.new(0,0,1), self.object:get_rotation())
|
||||||
for k, obj in pairs(objs) do
|
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 6)), true, false)
|
||||||
local ok = false
|
for hitpoint in raycast do
|
||||||
-- Arrows can only damage players and mobs
|
if hitpoint.type == "object" and hitpoint.ref ~= self._shooter then
|
||||||
if obj:is_player() then
|
local ok = false
|
||||||
ok = true
|
if hitpoint.ref:is_player() then
|
||||||
elseif obj:get_luaentity() then
|
|
||||||
if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then
|
|
||||||
ok = true
|
ok = true
|
||||||
|
elseif hitpoint.ref:get_luaentity() then
|
||||||
|
if (hitpoint.ref:get_luaentity().is_mob or hitpoint.ref:get_luaentity()._hittable_by_projectile) then
|
||||||
|
ok = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
if ok then
|
||||||
|
local dist = vector.distance(hitpoint.ref:get_pos(), pos)
|
||||||
if ok then
|
closest_object = hitpoint.ref
|
||||||
local dist = vector.distance(pos, obj:get_pos())
|
|
||||||
if not closest_object or not closest_distance then
|
|
||||||
closest_object = obj
|
|
||||||
closest_distance = dist
|
|
||||||
elseif dist < closest_distance then
|
|
||||||
closest_object = obj
|
|
||||||
closest_distance = dist
|
closest_distance = dist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If an attackable object was found, we will damage the closest one only
|
|
||||||
|
|
||||||
if closest_object then
|
if closest_object then
|
||||||
local obj = closest_object
|
local obj = closest_object
|
||||||
local is_player = obj:is_player()
|
local is_player = obj:is_player()
|
||||||
|
|
Loading…
Reference in New Issue