Shade can be damaged through glass.

This commit is contained in:
JetBoom 2014-11-09 05:11:22 -05:00
parent ae4c103a42
commit dcaaf991d9
2 changed files with 15 additions and 2 deletions

View file

@ -22,7 +22,7 @@ function ENT:Think()
local eyepos = pl:GetShootPos() local eyepos = pl:GetShootPos()
local nearest = owner:NearestPoint(eyepos) local nearest = owner:NearestPoint(eyepos)
local dist = eyepos:Distance(nearest) local dist = eyepos:Distance(nearest)
if dist <= 300 and TrueVisible(eyepos, nearest) then if dist <= 300 and LightVisible(eyepos, nearest, owner, pl) then
local dot = (nearest - eyepos):GetNormalized():Dot(pl:GetAimVector()) local dot = (nearest - eyepos):GetNormalized():Dot(pl:GetAimVector())
if dot >= 0.85 then if dot >= 0.85 then
local damage = (1 - dist / 300) * dot * 7 local damage = (1 - dist / 300) * dot * 7
@ -40,7 +40,7 @@ function ENT:Think()
local eyepos = ent:GetSpotLightPos() local eyepos = ent:GetSpotLightPos()
local nearest = owner:NearestPoint(eyepos) local nearest = owner:NearestPoint(eyepos)
local dist = eyepos:Distance(nearest) local dist = eyepos:Distance(nearest)
if dist <= 500 and TrueVisibleFilters(eyepos, nearest, owner, ent) then if dist <= 500 and LightVisible(eyepos, nearest, owner, ent) then
local dot = (nearest - eyepos):GetNormalized():Dot(ent:GetSpotLightAngles():Forward()) local dot = (nearest - eyepos):GetNormalized():Dot(ent:GetSpotLightAngles():Forward())
if dot >= 0.85 then if dot >= 0.85 then
local damage = (1 - dist / 500) * dot * 8 local damage = (1 - dist / 500) * dot * 8

View file

@ -60,6 +60,19 @@ function TrueVisibleFilters(posa, posb, ...)
return not util.TraceLine({start = posa, endpos = posb, filter = filt, mask = MASK_SHOT}).Hit return not util.TraceLine({start = posa, endpos = posb, filter = filt, mask = MASK_SHOT}).Hit
end end
MASK_SHOT_OPAQUE = bit.bor(MASK_SHOT, CONTENTS_OPAQUE)
-- Literally if photon particles can reach point b from point a.
function LightVisible(posa, posb, ...)
local filter = {}
if ... ~= nil then
for k, v in pairs({...}) do
filter[#filter + 1] = v
end
end
return not util.TraceLine({start = posa, endpos = posb, mask = MASK_SHOT_OPAQUE, filter}).Hit
end
function WorldVisible(posa, posb) function WorldVisible(posa, posb)
return not util.TraceLine({start = posa, endpos = posb, mask = MASK_SOLID_BRUSHONLY}).Hit return not util.TraceLine({start = posa, endpos = posb, mask = MASK_SOLID_BRUSHONLY}).Hit
end end