How should I get the muzzle position of a SWEP's viewmodel?

I’ve made this function:



function SWEP:GetMuzzlePos()
	if !IsValid(self) then return nil end
	if !IsValid(self.Owner) then return nil end
	local ply=self.Owner
	local vm = ply:GetViewModel()
	local obj = vm:LookupAttachment( self.MuzzleAttachment )
	local muzzlepos = vm:GetAttachment( obj )
	return muzzlepos 
end


But the Z coordinate is way off and seems to draw a cross at the player’s feet when I use debugoverlay.Cross. Any ideas? The offset does seem to work somewhat and get the correct X and Y coordinates, and I’m using the correct name in self.MuzzleAttachment.