Merge pull request 'Raytraced_arrows_fix' (#2297) from Raytraced_arrows_fix into master
Reviewed-on: MineClone2/MineClone2#2297
This commit is contained in:
commit
fab6cf8152
|
@ -410,29 +410,34 @@ function ARROW_ENTITY.on_step(self, dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate through all objects and remember the closest attackable object
|
-- Iterate through all objects and remember the closest attackable object
|
||||||
for k, obj in pairs(objs) do
|
local arrow_dir = self.object:get_velocity()
|
||||||
local ok = false
|
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||||
-- Arrows can only damage players and mobs
|
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
||||||
if obj:is_player() then
|
for hitpoint in raycast do
|
||||||
ok = true
|
if hitpoint.type == "object" then
|
||||||
elseif obj:get_luaentity() then
|
-- find the closest object that is in the way of the arrow
|
||||||
if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then
|
local ok = false
|
||||||
|
if hitpoint.ref:is_player() 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
|
if not closest_object or not closest_distance then
|
||||||
local dist = vector.distance(pos, obj:get_pos())
|
closest_object = hitpoint.ref
|
||||||
if not closest_object or not closest_distance then
|
closest_distance = dist
|
||||||
closest_object = obj
|
elseif dist < closest_distance then
|
||||||
closest_distance = dist
|
closest_object = hitpoint.ref
|
||||||
elseif dist < closest_distance then
|
closest_distance = dist
|
||||||
closest_object = obj
|
end
|
||||||
closest_distance = dist
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- If an attackable object was found, we will damage the closest one only
|
-- If an attackable object was found, we will damage the closest one only
|
||||||
|
|
||||||
if closest_object then
|
if closest_object then
|
||||||
|
|
|
@ -210,29 +210,34 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate through all objects and remember the closest attackable object
|
-- Iterate through all objects and remember the closest attackable object
|
||||||
for k, obj in pairs(objs) do
|
local arrow_dir = self.object:get_velocity()
|
||||||
local ok = false
|
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||||
-- Arrows can only damage players and mobs
|
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
||||||
if obj ~= self._shooter and obj:is_player() then
|
for hitpoint in raycast do
|
||||||
ok = true
|
if hitpoint.type == "object" then
|
||||||
elseif obj:get_luaentity() then
|
-- find the closest object that is in the way of the arrow
|
||||||
if obj ~= self._shooter and obj:get_luaentity().is_mob then
|
local ok = false
|
||||||
|
if hitpoint.ref:is_player() 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
|
if not closest_object or not closest_distance then
|
||||||
local dist = vector.distance(pos, obj:get_pos())
|
closest_object = hitpoint.ref
|
||||||
if not closest_object or not closest_distance then
|
closest_distance = dist
|
||||||
closest_object = obj
|
elseif dist < closest_distance then
|
||||||
closest_distance = dist
|
closest_object = hitpoint.ref
|
||||||
elseif dist < closest_distance then
|
closest_distance = dist
|
||||||
closest_object = obj
|
end
|
||||||
closest_distance = dist
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- If an attackable object was found, we will damage the closest one only
|
-- 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
|
||||||
|
|
Loading…
Reference in New Issue