Set rope vector as Toolgun muzzle position?

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.

I am pretty sure you can’t get view model attachment positions on server.

What should I be getting then? Can’t I just call a clientside script then or something (probably with the net library)? There aren’t any errors for me, it just doesn’t work.

First of all you should test if you even can attach a rope to a player. If you can, then you should be bothering about getting attachment positions.

[editline]12th April 2015[/editline]

I can tell you right now that you won’t be able to make an actual rope ( like the rope tool ) to look like it is coming out of your toolgun muzzle without rendering a custom rope on all clients and having an invisible rope on the server that actually affects the attached entities.

Doesn’t something like the Spiderman SWep do something like what you’re looking for?

The rope that I have currently does actually pull entities toward you if you run away, but it looks like it’s coming out of your feet rather than the toolgun. Surely there’s some sort of vector math possible to localize the muzzle to the player, even just to get a temporarily good-looking rope?

[editline]12th April 2015[/editline]

This one line=



Rope = constraint.Rope(self:GetOwner(), trace.Entity, 0, trace.PhysicsBone or 0, ( self:GetOwner():EyeAngles():Forward() + Vector(0, -10, 55)), trace.Entity:WorldToLocal(trace.HitPos), (self:GetOwner():GetPos()+Vector(0, 0, 35)):Distance(trace.HitPos), 0, 0, 20, "grapplertool/tool_tracer", false)


Is as close to the muzzle as I can get, the only problem is the vector is more up or more down depending on what angle you fire at.