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