below a video showing whats wrong. the red dot should be in the middle of the crosshair but it moves when i zoom in and out. but if i put my cursor off of the wall and zoom in and out it works fine
External Mediabelow the code
local firePart = self.fireParts[1].part
local origin, direction = self:getFireInfo(firePart)
raycastParams.FilterDescendantsInstances = {self.model, plr.Character, table.unpack(DEFAULT_BLACKLIST)}
local result = workspace:Raycast(origin, direction, raycastParams)
local pos
if result then
pos = result.Position
else
pos = (firePart.CFrame * NEGATIVE_10K_CFRAME).Position
end
local vector, inViewport = camera:WorldToViewportPoint(pos)
if inViewport then
if not aimMarker.Visible then
aimMarker.Visible = true
end
aimMarker.Position = UDim2.fromOffset(vector.x, vector.y)
elseif aimMarker.Visible then
aimMarker.Visible = false
end