Thrown physics object welding

I’m in the process of developing a SWEP that throws objects (how uncommon). How would I go about making the thrown objects weld themselves to wherever they hit? Help would be appreciated.

This sounds like a neat idea for creating statues and stuff, hope you figure it out.

Basically, on ENT.Touch in the thrown object, use constraint.Weld on “self” and “hitent”

So, something like this in the code creating the physics object?
[lua]
if(hitEnt:IsValid()) then
constraint.Weld(self,hitent,0,0,true)
end
[/lua]

Try it, it should work.

This would be a really cool thing to have :smiley: Fun to play with.

Trying it now…

EDIT:
OK, so here’s mah function:
[lua]function ENT:Touch(hitEnt)
if(hitEnt:IsValid()) then
constraint.Weld(self,hitent,0,0,true)
end
end[/lua]

and its run in the primary fire, but I get a spiffy Lua error telling me it lacks arguments. I have no idea what that means.

I’m not sure if it’s required, but you are missing “Bone 1” in your constraint.Weld(). Check the wiki again :stuck_out_tongue:

The bones argument is already in there (The two 0’s).

Can you give us the exact error?

snip

it says “function arguments expected near ‘cleanup’”

Well can you post the code that contains ‘cleanup’?

[lua]
self:hitEnt

cleanup.Add (self.Owner, "props", ent);

undo.Create ("A Nerf Dart");
undo.AddEntity (ent);
undo.SetPlayer (self.Owner);
undo.Finish();[/lua]

[lua]
self:hitEnt()

cleanup.Add (self.Owner, "props", ent);

undo.Create ("A Nerf Dart");
undo.AddEntity (ent);
undo.SetPlayer (self.Owner);
undo.Finish();[/lua]

Like the error said you forgot function arguments. ()
You should probably post your whole code for a definitive and total answer.
Because unless you defined that function yourself I get the feeling you’re doing it wrong.
So the code of both the SWEP and the thrown entity.