• Weld Not Welding But Deleting
    2 replies, posted
Hello, I'm trying to weld a prop to another entity upon collision. I've checked to make sure the constraint is in fact being created. Setting deleteent1onbreak to true will delete the prop, but the weld doesn't actually attach the two together.. [url]http://wiki.garrysmod.com/page/constraint/Weld[/url] What's going on here? [code] function ENT:Initialize() self:SetModel( "models/dx/terminals/dx_terminal_upgrades.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.MaxHealth = 10000 self:SetHealth( self.MaxHealth ) self.AttachWeld = nil self.AttachedEnt = nil local Plug = ents.Create( "prop_physics" ) Plug:SetModel( "models/props_lab/tpplug.mdl" ) Plug:SetPos( self:GetPos()+Vector(-30,0,55) ) Plug:SetAngles( Angle(0,0,180) ) Plug:Spawn() Plug:Activate() Plug:SetTrigger( true ) Plug:AddCallback( "PhysicsCollide", function( PlugEnt, colData ) if ( colData.DeltaTime > 0.1 ) then for _,v in pairs( ents.FindInSphere( PlugEnt:GetPos(), 15 ) ) do if ( not IsValid( self.AttachedEnt ) and v.DX_Upgrades ) then print(v:GetClass()) self.AttachedEnt = v self.AttachWeld = constraint.Weld( v, PlugEnt, 0, 0, 0, true, true ) print(self.AttachWeld) end end end end ) self.Elastic, self.Rope = constraint.Elastic( Plug, self, 0, 0, Vector(10,0,0), Vector(16,0,55), 2000, 3, 0.01, "cable/cable2", 3, 0 ) self.Plug = Plug self:GetPhysicsObject():EnableMotion( false ) end[/code]
You can't do constraints in the physicscollide callback. A vphysics error will appear and since garry implemented so physics errors remove the entities instead of crashing the game, they dissapear. To get around this, wrap it around a timer.Simple(0,function()end)
Thank you my good sir! King for you!
Sorry, you need to Log In to post a reply to this thread.