Sentry: shoot players at eye height

This commit is contained in:
marco_a 2024-10-28 01:43:35 +01:00
parent 4bcb63b5b7
commit f0b8e149ee

View File

@ -110,10 +110,11 @@ local sentry_gun = {
if not is_player and self._owner == ent_lua._owner then return end
-- TODO: non so perché continua a crashare, per ora evito
-- TODO: volevo calcolare l'altezza a seconda dell'ingombro di collisione (quindi
-- sia entità che giocanti) ma non so perché continua a crashare. Per ora evito le entità
--shooting_height = vector.new(0, (collisionbox[5] + math.abs(collisionbox[2])) / 2, 0) -- altezza media
--to_target_dir = vector.direction(s_pos, vector.add(obj:get_pos(), shooting_height))
to_target_dir = vector.direction(s_pos, obj:get_pos())
shooting_height = vector.new(0, is_player and obj:get_properties().eye_height or 0, 0)
to_target_dir = vector.direction(s_pos, vector.add(obj:get_pos(), shooting_height))
angle = math.deg(vector.angle(to_target_dir, dir))
if math.abs(angle) <= 60 and obj:get_hp() > 0 then
@ -145,14 +146,12 @@ local sentry_gun = {
minetest.after(0.3, function() -- 2° colpo
-- se controllo solo obj e l'obiettivo si è sconnesso, passa il controllo
if not target:get_pos() or not self.object or self._is_dying then return end
--to_target_dir = vector.direction(s_pos, vector.add(target:get_pos(), shooting_height))
to_target_dir = vector.direction(s_pos, target:get_pos())
to_target_dir = vector.direction(s_pos, vector.add(target:get_pos(), shooting_height))
rotate_and_shoot(sentry, to_target_dir)
minetest.after(0.3, function() -- 3° colpo
if not target:get_pos() or not self.object or self._is_dying then return end
--to_target_dir = vector.direction(s_pos, vector.add(target:get_pos(), shooting_height))
to_target_dir = vector.direction(s_pos, target:get_pos())
to_target_dir = vector.direction(s_pos, vector.add(target:get_pos(), shooting_height))
rotate_and_shoot(sentry, to_target_dir)
end)
end)