PhysicsCollide being called too early

Hey all, I decided to work on a swep that shoots a sent with particle effects, to look somewhat like a plasma weapon. I have an explosion particle effect that is called on ENT:OnRemove(), and it all works fine on single player, however, it seems that in multiplayer, it’s being called too early, or it’s something with prediction. It’ll be removed and the explosion effect will be off the wall/entity by quite a bit. Is there any way to sync the effect and such up to where it’ll be removed exactly when it hits a wall or entity?

I’ll provide some code if that doesn’t make sense.

The server and client aren’t always synced up in multiplayer, so most times there will be a little bit of off-ness. I’m not entirely sure if there is anyway to fix it but its the same thing with trailing hitboxes and whatnot.
The source engine is notorious for things like that.

I fixed it up, to where it hits entities directly, and I was using IsInWorld to have it correctly hit walls. However, it seems that IsInWorld doesn’t take thing walls into account. Is there any way to check if it’s on, or in a wall to trigger removing of the entity?

Why don’t you update a trace on each think and check if Hit && HitWorld?

Try firing the effects in **[ENT.PhysicsCollide

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=ENT.PhysicsCollide)**, it’s called when your entity collides with another or the world.

EDIT:
It’s server side so if you are using client side effects, us the **[Entity.DTVar

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.DTVar)** and **[ENT.SetupDataTables

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=ENT.SetupDataTables)**, and set a boolean for when the effects should fire, and check for it in the think of the client, and play the effect when it becomes true. Hope this helps.

Physicscollide was being weird, so I took Commander’s advice, and it works. Here’s a sample of how it works.

init.lua



function ENT:Initialize()
    self:SetModel( "models/Gibs/HGIBS.mdl" )
    self:PhysicsInit( SOLID_VPHYSICS )   
    self:SetMoveType( MOVETYPE_VPHYSICS )  
    self:SetTrigger(true)
    self:SetNotSolid(true)
    
    self:SetColor(0,0,0,0)
        local phys = self:GetPhysicsObject()
        phys:EnableGravity(false)
        phys:SetMass(1)
        phys:SetBuoyancyRatio( 0 )
        if (phys:IsValid()) then
            phys:Wake()
        end
end
  
function ENT:Touch(HitEntity)
    if HitEntity:IsNPC() and HitEntity:Health() > 0 then
        HitEntity:TakeDamage(self.LP:GetNWFloat("pisDmg"),self.LP,self.LP)
    end
    timer.Simple(0.1, function() if self:IsValid() then self:Remove() end end)
end
 
function ENT:PhysicsUpdate( phys )
    local pos = self:GetPos()
    local ang = self:GetForward()
    local tracedata = {}
    tracedata.start = pos
    tracedata.endpos = pos+(ang)
    tracedata.filter = self.Owner
    local trace = util.TraceLine(tracedata)
    if trace.HitWorld then
       self:Remove()
    end
end


The timer lets the sent get a bit closer to the entity it hit.
It’s pretty messy, but it works nicely. If there’s a better way to go about doing this, I’d love to know :slight_smile: