I’m trying to make a toolgun STool that attaches a rope from the player’s toolgun muzzle (vector) to wherever the player shoots the toolgun. I don’t want to attempt a SWEP as I’m just testing some things out. I tried converting the toolgun muzzle vector to a vector local to the player, but that didn’t work. The code is pretty horrible, so I’m sure someone will point out some stupidly obvious mistake. It’s like the wiremod laser, except it’s a rope that needs an entity to attach to (the player) and a vector local to the player to change the position of it. And no, I don’t want to render a line as the laser does.
local viewm = self:GetOwner():GetViewModel() local obj = viewm:LookupAttachment( "muzzle" ) local muzzlepos = viewm:GetAttachment( obj ) local muzzlevector = muzzlepos["Pos"] local noangle = Angle( 0, 0, 0 ) local betatest = WorldToLocal( muzzlevector, noangle, self:GetOwner():GetPos(), noangle ) Rope = constraint.Rope(self:GetOwner(), trace.Entity, 0, trace.PhysicsBone or 0, betatest, trace.Entity:WorldToLocal(trace.HitPos), (self:GetOwner():GetPos()+Vector(0, 0, 35)):Distance(trace.HitPos), 0, 0, 20, "MATERIAL PATH", false)
The problem with this code is that for some reason, it doesn’t work AT ALL.
Note that isn’t all the code of the tool (obviously), and this part is inside TOOL:LeftClick, with a few if statements to stop the rope being unjoinable to the target and such.
[editline]12th April 2015[/editline]
The main issue is localizing it to the player’s vector. I’m pretty horrible at vector math.