Entity Is Physgunnable outside of it's Collision Bounds?
2 replies, posted
I'm working on an entity that I expect to be physgunnable only within it's collision bounds, but acts unexpectedly both within and outside bounds. Like you can physgun into the middle of the box and not grab it. It's just a box that you can edit the size of represented by a wireframe box, which I expect to be grab-able.
I'm resetting the collision area on any box size change, and it sometimes works, but never exactly as expected. Any help would be appreciated.
function ENT:SetupDataTables()
self:NetworkVar("Vector",0,"MinBound",{KeyName="minbound", Edit={type="Vector",order=1}})
self:NetworkVar("Vector",1,"MaxBound",{KeyName="maxbound", Edit={type="Vector",order=2}})
self:NetworkVarNotify("MinBound", self.OnBoundsChanged)
self:NetworkVarNotify("MaxBound", self.OnBoundsChanged)
if(SERVER) then
self:SetMinBound(Vector(-5,-5,-5))
self:SetMaxBound(Vector(5,5,5))
self:SetColor(Vector(255,0,0))
end
end
function ENT:SpawnFunction( ply, tr, ClassName )
if ( !tr.Hit ) then return end
local ent = ents.Create( ClassName )
ent:SetPos( tr.HitPos + tr.HitNormal)
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Initialize()
self:SetModel("")
self:SetMoveType(MOVETYPE_NONE)
self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
self:RebuildPhysics()
end
function ENT:RebuildPhysics()
self:PhysicsInit(SOLID_OBB)
self:SetSolid(SOLID_BBOX)
self:SetCollisionBounds(self:GetMinBound(), self:GetMaxBound())
end
function ENT:UpdateTransmitState()
return TRANSMIT_ALWAYS
end
function ENT:OnBoundsChanged(varname, oldvalue,newvalue)
self:RebuildPhysics()
if(SERVER) then return end
self:SetRenderBounds(self:GetMinBound(), self:GetMaxBound())
end
function ENT:Draw()
local vec1, vec2 = self:GetCollisionBounds()
cam.Start3D()
render.DrawWireframeBox(self:GetPos(), self:GetAngles(), vec1,vec2, self:GetColor())
render.DrawWireframeSphere(self:GetPos(), 5, 10, 10)
cam.End3D()
end
So take a look at the example script here, and you should definitely be able to solve your issue. I had just tested with the exact script and it works as expected with setting new physics bounds.
CreatePhysCollideBox
yeah that works cheers bro!
Sorry, you need to Log In to post a reply to this thread.