Better solution for SetRenderOrigin

Hello,
I have a problem with the position of the weapons on a playermodel. The model is holding the weapon in the hand but the weapon is flickering when he is moving.
Here is my DrawModel code:



SWEP.Offset = {
   Pos = {
      Up = 0,
      Right = 0,
      Forward = 0,
   },
   Ang = {
      Up = 0,
      Right = 0,
      Forward = 180,
   }
}

function SWEP:DrawWorldModel( )
	if ( SERVER ) then return end
        local hand, offset, rotate

        local pl = self:GetOwner()

        if IsValid( pl ) then
                        local boneIndex = pl:LookupBone( "ValveBiped.Bip01_R_Hand" )
                        if boneIndex then
                                local pos, ang = pl:GetBonePosition( boneIndex )
                                pos = pos + ang:Forward() * self.Offset.Pos.Forward + ang:Right() * self.Offset.Pos.Right + ang:Up() * self.Offset.Pos.Up

                                ang:RotateAroundAxis( ang:Up(), self.Offset.Ang.Up)
                                ang:RotateAroundAxis( ang:Right(), self.Offset.Ang.Right )
                                ang:RotateAroundAxis( ang:Forward(),  self.Offset.Ang.Forward )

                                self:SetRenderOrigin( pos )
                                self:SetRenderAngles( ang )
                                self:DrawModel()
                        end
        else
                self:SetRenderOrigin( nil )
                self:SetRenderAngles( nil )
                self:DrawModel()
        end
end

Hopefully you can help me.

Maksimo007

I’ve noticed a lot of weapons have been doing this. Is it possible to parent the gun to the bone?

This would be nice, hopefully somebody knows this