• Custom Viewmodel Anchor System
    0 replies, posted
Hey, I'm trying to write a system that allows the user to make their own viewmodel attachments with just lua. For some reason, though, it seems to be getting a completely incorrect position for the bone. Any ideas? [code] SWEP.VMAnchors = { [1] = { bone = "Base", pos = Vector(0,0,0), angle = Angle(0, 0, 0) } } local posvec = Vector() local angang = Angle() function SWEP:GetAnchor(id) if !self:OwnerIsValid() then return end local ifp = self:IsFirstPerson() local targent = ifp and self.Owner:GetViewModel() or self local tbl if ifp then tbl = self.VMAnchors[id] or self.VMAnchors[tonumber(id)] end if tbl then local bone if type(tbl.bone) == "string" then bone = targent:LookupBone(tbl.bone) end if type(tbl.bone) == "number" then bone = tbl.bone end if !bone or bone<=0 then bone = 1 end local pos, ang = posvec,angang local m = targent:GetBoneMatrix(bone) if (m) then pos, ang = m:GetTranslation(), m:GetAngles() end if (ifp and self.ViewModelFlip) then ang.r = -ang.r end local newpos,newang = LocalToWorld(tbl.pos,tbl.angle,pos,ang) debugoverlay.Cross(newpos,5,0.1,color_white,true) return newpos, newang else if type(id) == "number" then local angpos = targent:GetAttachment(id) return angpos.Pos,angpos.Ang else local ind = targent:LookupAttachment(id) if !ind or ind<=0 then ind=tonumber(id) end if !ind or ind<=0 then ind=1 end local angpos = targent:GetAttachment(ind) return angpos.Pos,angpos.Ang end end end [/code] Screenshot: [t]http://vgy.me/fDogtM.jpg[/t] Keep in mind that "Base" is the root bone of the gun and the normal .qc muzzle attachment works fine.
Sorry, you need to Log In to post a reply to this thread.