Camera flicking in weird ways when passing through portal

I am using EgoMoose’s portal system. I modified it to allow me to choose what portal I put down. For some reason when passing through a portal your camera will flick.

I figured out it takes your camera vertical rotation and negatives it. how do I fix this?

code:

function PortalPhysics:MoveRoot(from, to)
	local camCF = self.Camera.CFrame
	local rootCF, rootVel = self.RootPart.CFrame, self.RootPart.Velocity
	local fromCF: CFrame = getSurfaceInfo(from)
	local toCF: CFrame = getSurfaceInfo(to)
	
	local cameraOffset = (fromCF:Inverse()) * camCF
	local newCamCF = toCF * cameraOffset * Y_SPIN
	
	-- get the twist of the hrp
	local swing, twist = swingTwist(rootCF, rootCF:VectorToObjectSpace(UP))
	
	local camRootOffset = rootCF:Inverse() * camCF
	local rootOffset = fromCF:Inverse() * rootCF
	local newRootCF = CFrame.new((toCF * Y_SPIN * rootOffset).p) * twist * Y_SPIN
	local down = math.max(0, toCF:ToObjectSpace(newRootCF * CFrame.new(0, camRootOffset.y, 0)).z)
	newRootCF = newRootCF + toCF.LookVector*down
	
	local newVelocity = (toCF * Y_SPIN):VectorToWorldSpace(fromCF:VectorToObjectSpace(rootVel))
	
	self.Camera.CFrame = newCamCF
	self.RootPart.CFrame = newRootCF
	self.RootPart.Velocity = newVelocity
end

vid:

Try this to keep the camera level stable:

local lookVector = currentCFrame.LookVector
local upVector = currentCFrame.UpVector
local rightVector = currentCFrame.RightVector

local newCFrame = CFrame.fromMatrix(newPosition, rightVector, upVector, -lookVector)

Tested and Trusted, this keeps the camera level exactly the same when teleporting

1 Like

I found the solution:

local CamX, CamY, CamZ = camCF:ToEulerAnglesXYZ()
	
	local cameraOffset = fromCF:Inverse() * (CFrame.new(camCF.Position) * CFrame.Angles(-CamX, CamY, CamZ))

WHY IS IT THAT EVERYTIME I MAKE A POST I FIND THE SOLUTION DIRECTLY AFTERWARDS (I have been trying to fix this for a while now)

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