Viewportframe getting distorted when on surfacegui

ok so basically i am trying to make a portal from portal, and i know there are SO many other posts and stuff explaining it with open source, but i just cant understand the math and i am trying to make it myself instead

i have been making my portal using viewport frames and because they are flat they get distorted, which is to be expected, so im wondering what kind of math i can use to counter this

it works fine when i make the portal face toward the player, but this is not a permanent solution

so can somebody explain what the math needed to solve the issue for before or explain the math from another open source portal

video demonstrating this

code used
	local startPart = longA
	local endPart = longA
	--line of code to make portal face player \/
	startPart.CFrame =,,startPart.Position.Y,player.Character.HumanoidRootPart.Position.Z))

	local lookFrame =, startPart.Position)
	local lookAngle = lookFrame.LookVector

	local distance = camera.CFrame.Position - startPart.Position

	ncamera.CFrame =, endPart.Position + lookAngle) + distance
	local size = distance.Magnitude/5
	viewportFrame.Size = UDim2.fromScale(size,size)
video used to make portal

sorry if i didnt explain it well i can answer any questions