Line Of Sight indicator script offset camera problem with custom camera manipulation

So, I have a Line of sight indicator with a roblox gun script, and it works perfectly with no camera offsets whatsoever. The problem arises when the camera is offset to the right using the SmoothShiftLock module.

Here is it working perfectly, without any camera offset:

Here it is with the camera offset:

In other instances however the camera offset and LOS indicator script works perfectly:

Here is the code block responsible for the LOS indicator:

if self.LOSEnabled and not self.sprinting then
	local LOSIndicatorParams = RaycastParams.new()
	LOSIndicatorParams.FilterType = Enum.RaycastFilterType.Exclude
	LOSIndicatorParams.FilterDescendantsInstances = {self, player.character}
	local mousepos = player.mouse.Hit.Position
	local barrel_pos = self.grip.Barrel.WorldPosition
	local indicatorRange = 5000
	local direction = (mousepos - barrel_pos).Unit
	local aimDirecton

	if workspace.CurrentCamera:GetAttribute("OffsetValue") == Vector3.new(0,0,0) then
		local direction = (mousepos - barrel_pos).Unit
		aimDirection = direction
	else
		local adjustedCameraCFrame = workspace.CurrentCamera.CFrame * CFrame.new(workspace.CurrentCamera:GetAttribute("OffsetValue"))
		aimDirection = (adjustedCameraCFrame.Position + adjustedCameraCFrame.LookVector * 1000 - barrel_pos).Unit
	end

	local LOSIndicatorRay = workspace:Raycast(barrel_pos, aimDirection * indicatorRange, LOSIndicatorParams)

	if LOSIndicatorRay then
		local newPos = self.LOSAttachment.WorldCFrame:Lerp(CFrame.new(LOSIndicatorRay.Position), 0.5)
		self.LOSAttachment.WorldCFrame = newPos
		--self.LOSAttachment.WorldPosition = LOSIndicatorRay.Position
		self.LOSBeam.Enabled = true
		self.LOSCrosshair.Enabled = true
	else
		self.LOSAttachment.WorldPosition = barrel_pos + aimDirection * indicatorRange
		--self.LOSBeam.Enabled = false
		--self.LOSCrosshair.Enabled = false
	end
else
	self.LOSBeam.Enabled = false
	self.LOSCrosshair.Enabled = false
end

Despite the camera being offset, the MousePos should still return correct results, and I was able to confirm this with the SmoothShiftLock module.
I assume the X symbol is your hit position, and the Dot is the mouse position.

Have you tried just passing aimDirection as direction always, to me it feels unnecessary, unless in this case it is.
Alternatively, perhaps try using something like aimDirection = CFrame.new(barrel_pos, mousepos).LookVector which might work. It is ever so slightly less prone to error.

Without more information, or a .rbxl file to debug with, I can’t really do more than guess on underlying functions

So, passing direction and your proposed solution everytime results in this:


I use that whole complicated camera thing because without it the result above happens. It does genuinely work well in some cases but in others it’s pretty bad. What can I provide you to help debug? Like, what underlying functions? In principle it should just be a ray cast out from the position of the barrel to the mouse position, and seeing if anything intersects there. When it intersects it just puts an attachment there with a beam connected to the barrel. The barrel itself is an attachment too.

And yes, you’re right, the dot is the mouse position and the X is where the projected hit is. The system I’m using is NoCol, which uses a raycast from the barrel towards the mouse position. It uses the FastCast module.

The shift lock camera offset is this:

LOCKED_CAMERA_OFFSET        = Vector3.new(2.25, 1, -2.5),