Camera flasing bugs

i want a smooth camera between the portals but when the camera or character goes through the portal there are some flashes as seen below.


the scripts controlling this is below and i dont know why the camera flashes like that.

--module script
function Portal:GetCameraPassThrough()
	local portalPart = self:GetPart()
	local camera = workspace.CurrentCamera
	
	local result = Helpers.raycast(workspace, camera.Focus.Position, (camera.CFrame.Position - camera.Focus.Position), {
		FilterType = Enum.RaycastFilterType.Include,
		Instances = {portalPart},
	})

	if result and result.Normal:Dot(portalPart.CFrame.ZVector) <= -0.999 then
		local fromSurface = self:GetSurface()
		local toSurface = self.linked:GetSurface()
		toSurface = toSurface * Y_SPIN
		
		local newCFrame = toSurface * fromSurface:ToObjectSpace(camera.CFrame)
		local newFocus =  toSurface * fromSurface:ToObjectSpace(camera.Focus)

		return true, newCFrame, newFocus
	end

	return false
end
--control script
local success, cframe, focus = portal:GetCameraPassThrough()
	
if success then	-- Control camera collisions
	currentportal = key
	local cameraRay = Ray.new(focus.Position, cframe.Position - focus.Position)
	local Ignore = {player.Character}
	for i, part in ipairs(Portals:GetChildren()) do
		if part.Value ~= nil then
			table.insert(Ignore, part.Value)
		end
	end
	local block = true
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	while block == true do
		params.FilterDescendantsInstances = Ignore
		local HitPart = game.Workspace:Raycast(focus.Position, (Portals["Portal" .. portals[key][3]].Value.CFrame.Position - focus.Position), params)
		if HitPart ~= nil then
			table.insert(Ignore, HitPart.Instance)
		else
			block = false
		end
	end
				
	local HitPart, HitPosition = game.Workspace:FindPartOnRayWithIgnoreList(cameraRay, Ignore)
	workspace.CurrentCamera.Focus = focus
	workspace.CurrentCamera.CFrame = (cframe - (cframe.Position - HitPosition)) + (focus.Position - cframe.Position).Unit    
	cameraPortalSide = portal:GetLinked()
	if cam ~= "Invisicam" then
		script.Parent.Parent.Parent.PlayerGui:WaitForChild("Camera Mode"):FireServer("Invisicam")
		cam = "Invisicam"
	end
	break
else
	currentportal = ""
	if cam ~= "Zoom" then
		script.Parent.Parent.Parent.PlayerGui:WaitForChild("Camera Mode"):FireServer("Zoom")
		cam = "Zoom"
	end
end
2 Likes

bumping this as its been a hour

1 Like

Not enough to work with here … would need the viewport script and model also.
Sorry, start a new program, copy both them files, follow your instructions and see how far you get.

1 Like

A dozen examples of that super secret code … Viewport portal effect … Good luck!
This one is pretty much flawless … The Portal

its a issue with the camera, not the veiwport. the only model used is a basic part. please actually answer my questin.

bumping this as its been 6 hours.

Looks like the camera is moving closer because it is hitting a part. If your portals (the parts) have collision, you could try disabling that and seeing if it works.

i think the issue is caused becuase the camera is colliding with something in the fake character. how can i set something to have collision but not collide with the default camera?

If you’re okay with forking the player modules, you could try this solution: How can I set the camera to a Collision Group? If not, you could try to disable the collisions of the fake character locally since the server should handle all the physics and the client’s camera will pass through.

can i call the functions CharacterAdded and CharacterRemoving from my scripts as its in the module script?

bumping this as its been 18 hours.