camera:WorldToViewportPoint outputting wrong when camera zooms in and out

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 Media

below 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

i fixed it, i forgot the direction output from getFireInfo isnt long enough to reach those far out parts, so i multiplied by 1000

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.