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