Need help with an Electric Fence entity.

Hi, i’m trying to make an electric fence entity and having some troubles.

I need it to be:

  • Physgunnable
  • Nocollided with players, yet still trigger ENT:Touch()
  • Shootable

Heres what i’ve got so far, in entities\electric_fence\init.lua

[lua]
function ENT:Initialize()

local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
    phys:Wake()
    phys:SetMass(50)
    phys:EnableMotion(false)
end

self:SetTrigger( true )
self:SetNotSolid( true )

end

function ENT:Touch( ply )
if( ply:IsPlayer() && ply != self.Owner && ( ply:Team() == 1 || ply:Team() != self.Owner:Team() ) ) then
self:SetMaterial( “models/alyx/emptool_glow” )
timer.Destroy( tostring( self ) … “fence” )
timer.Create( tostring( self ) … “fence”, 0.2, 1, function() self:SetMaterial( self.item.material ) end )
self:EmitSound( “weapons/physcannon/superphys_launch1.wav”, 300, 200 )
ply:TakeDamage( 5, self.Owner, self.Owner )
end
end
[/lua]

If it’s not solid, I don’t believe ENT:Touch will work. You may have better luck setting it to self:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER ) which may or may not still allow ENT:Touch while being nocollide.

^That. Learned from personal experience. Also, if it needs to hit nonsolid objects/players, try using ents.FindInBox with small bounds.

It should work if he has SetTrigger set to true.

And what exactly is the issue?

I once made (as part of a weapon) an entity that didn’t collide with stuff but still reacted to touch using Ent:StartTouch() and SetTrigger(True) and SetNotSolid(true). It wasn’t shootable though, bullets went right through it.