I’d like to make it so that the smoke from a smoke grenade will block a player’s line of sight to another player and prevent their name tag from drawing. Could anyone offer some information on how I could achieve this? I’ve been looking at util/TraceEntity, Structures/Trace, Enums/MASKStructures/TraceResult but the descriptions given are quite vague.
In relation to this, I’d also like to know how I could create an “invisible shape”, such as a sphere that can vary in size. If I could create this, could I check if a trace were to go through it and determine line of sight that way?
Apply a variable to the player like Player.IsBlinded, then modify the tag drawing function to run a check
[lua]if LocalPlayer().IsBlinded then return end[/lua]
It’ll require more than that, because you have to send the variable to player and do some ‘thinking’ about where to hook the function that blinds the player and takes blind off.
I may or may not have forgotten SetCollisionBounds, which actually determines the “trace” size of the object. The Collision and Physics bounds are different. Try self:SetCollisionBounds(Vector(-450, -450, -450),Vector(450, 450, 450))
Also, on the trace part, a normal trace without any specified Masks would work. I’m assuming you’re calling this from a player, then PLAYER:GetEyeTrace should do the trick. It’s basically a util.QuickTrace, which is a convience function (using GetEyePos and GetEyeAngles:Normalize()), because you don’t have to specify anything but startpoint and a direction for a trace to work. Normally you don’t have to specify a mask unless you specifically only want to prevent picking up certain things, like brushes.
Thanks very much, it’s actually working. I’m really glad. The only problem remaining is that it now also blocks bullets. Do you know of any way to make it block only the eye traces, and not say a trace for a weapon attack?
Since you have enabled custom collisions, I think if you make the Entity report false in a collision hook with any player, any bullets will be blocked. I know that if you make players report false in a collision hook with an entity they cannot shoot it, so the reverse should apply.
If you do self:SetCustomCollisionCheck(true) in the entity’s initialization, then set some variable on it like self.NoPlayerCollision = true, then add this hook at the bottom:
hook.Add(“ShouldCollide”, “ShouldCollide_SmokeGrenade”, function(e1, e2)
return !((e1.NoPlayerCollision or e2.NoPlayerCollision) and (e1:IsPlayer() or e2:IsPlayer()))
Thank you very much, it works like a treat. The only problem was that a melee weapon was still hitting it, but I just added the smoke entity to the filter bit of its trace structure. Works great, thanks again.