Allow entities to use get_pointed_objects as well (to damage objects)
This commit is contained in:
parent
5bd153a396
commit
e381407402
@ -1,6 +1,6 @@
|
|||||||
local function cast_raycast() end
|
local function cast_raycast() end
|
||||||
local function get_player_left_dir() end
|
local function get_shooter_left_dir() end
|
||||||
local function get_player_up_dir() end
|
local function get_shooter_up_dir() end
|
||||||
local function debug_particles() end
|
local function debug_particles() end
|
||||||
|
|
||||||
|
|
||||||
@ -34,12 +34,21 @@ minetest.register_entity("block_league:dummy", dummy)
|
|||||||
-- actually hardcoded because:
|
-- actually hardcoded because:
|
||||||
-- 1. it works and I don't need more features from it
|
-- 1. it works and I don't need more features from it
|
||||||
-- 2. I haven't got enough knowledge about vectors and rotations anyway
|
-- 2. I haven't got enough knowledge about vectors and rotations anyway
|
||||||
function block_league.get_pointed_objects(player, range, has_piercing)
|
function block_league.get_pointed_objects(shooter, range, has_piercing, entity_table)
|
||||||
|
local height, look_dir
|
||||||
|
|
||||||
|
if entity_table then
|
||||||
|
height = entity_table.height
|
||||||
|
look_dir = entity_table.dir
|
||||||
|
else
|
||||||
|
height = 1.475
|
||||||
|
look_dir = shooter:get_look_dir()
|
||||||
|
end
|
||||||
|
|
||||||
local hit_pointed_things = {}
|
local hit_pointed_things = {}
|
||||||
local left_dir = get_player_left_dir(player)
|
local left_dir = get_shooter_left_dir(shooter)
|
||||||
local head_up_dir = get_player_up_dir(player)
|
local head_up_dir = get_shooter_up_dir(shooter, look_dir)
|
||||||
local look_dir = player:get_look_dir()
|
local center = shooter:get_pos() + look_dir + {x=0, y=height, z=0}
|
||||||
local center = player:get_pos() + look_dir + {x=0, y=1.475, z=0}
|
|
||||||
|
|
||||||
local grid_width = 0.25
|
local grid_width = 0.25
|
||||||
local r_amount = 2
|
local r_amount = 2
|
||||||
@ -49,7 +58,7 @@ function block_league.get_pointed_objects(player, range, has_piercing)
|
|||||||
|
|
||||||
for row = 1, r_amount do
|
for row = 1, r_amount do
|
||||||
for column = 1, r_amount do
|
for column = 1, r_amount do
|
||||||
local pthings = cast_raycast(player, ray_pos, look_dir, range, has_piercing)
|
local pthings = cast_raycast(shooter, ray_pos, look_dir, range, has_piercing)
|
||||||
--debug_particles(look_dir, ray_pos, 30)
|
--debug_particles(look_dir, ray_pos, 30)
|
||||||
|
|
||||||
if pthings then
|
if pthings then
|
||||||
@ -113,7 +122,7 @@ function cast_raycast(user, origin, dir, range, has_piercing)
|
|||||||
end]]
|
end]]
|
||||||
|
|
||||||
-- se è un giocatore (e non chi spara)
|
-- se è un giocatore (e non chi spara)
|
||||||
elseif hit.ref:is_player() and hit.ref ~= user then
|
elseif hit.ref ~= user then
|
||||||
if (hit.intersection_point.y - hit.ref:get_pos().y) > 1.275 then
|
if (hit.intersection_point.y - hit.ref:get_pos().y) > 1.275 then
|
||||||
table.insert(objects, {object=hit.ref, headshot=true})
|
table.insert(objects, {object=hit.ref, headshot=true})
|
||||||
else
|
else
|
||||||
@ -121,8 +130,13 @@ function cast_raycast(user, origin, dir, range, has_piercing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local is_player = hit.ref:is_player()
|
||||||
|
local t_name = is_player and hit.ref:get_player_name() or hit.ref:get_luaentity().name
|
||||||
|
|
||||||
|
if not has_piercing then return objects end
|
||||||
|
|
||||||
else
|
else
|
||||||
-- se è un nodo mi fermo, e ritorno l'array se > 0 (ovvero ha trovato giocatorɜ)
|
-- se è un nodo mi fermo, e ritorno l'array se > 0 (ovvero ha trovato obiettivi)
|
||||||
if hit.type == "node" then
|
if hit.type == "node" then
|
||||||
if #objects > 0 then
|
if #objects > 0 then
|
||||||
return has_piercing and objects or {objects[1]}
|
return has_piercing and objects or {objects[1]}
|
||||||
@ -143,8 +157,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function get_player_left_dir(player)
|
function get_shooter_left_dir(shooter)
|
||||||
local yaw = player:get_look_horizontal()
|
local yaw = shooter:get_look_horizontal() or shooter:get_yaw()
|
||||||
local pl_left_dir = vector.new(math.cos(yaw), 0, math.sin(yaw))
|
local pl_left_dir = vector.new(math.cos(yaw), 0, math.sin(yaw))
|
||||||
|
|
||||||
return vector.normalize(pl_left_dir)
|
return vector.normalize(pl_left_dir)
|
||||||
@ -152,8 +166,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function get_player_up_dir(player)
|
function get_shooter_up_dir(shooter, dir)
|
||||||
return vector.rotate_around_axis(player:get_look_dir(), get_player_left_dir(player), math.pi/2)
|
return vector.rotate_around_axis(dir, get_shooter_left_dir(shooter), math.pi/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user