How can I have a camera follow a player along a line/curve between two cameras

So I want to create a camera dolly sliding track where the camera will follow the player along a path of cameras, with the camera CFrame being determined based off of a model full of parts, using their CFrames to interpolate between the cameras. I have created something that does some of the intended solution, albeit janky and has a few big issues. Below is a demonstration of it in action, with red and green part representing the relative position of each of the two CFrames, and the white part is where the camera would be.

The biggest problems with this are 1.) If the cameras are parallel or relatively parallel, the camera part is completely wrong in its position. 2.) Similarily, if the player is “behind” the axis, the system evidently does not work correctly, calculating weird angles for the “camera”. 3.) As the player gets farther away from the cameras(even if they walk directly parallel to the main camera), the position of the camera will drift closer to the player, even though I would like it to be snapped to an invisible curve or line (whichever is easier to implement). Is there a way I can modify the current code below to possibly fix these issues and/or should I go about using a different technique to achieve the intended result?

local camPart = script.Parent.CamPart
local dupCamPart = script.Parent.DupCamPart
local midCamPart = script.Parent.MidCamPart
local curCamGroup = script.Parent.Cam2

while task.wait() do
	local posA = curCamGroup.CFrame:PointToObjectSpace(player.Character.HumanoidRootPart.Position)
	if posA.X >= curCamGroup.CFrame:PointToObjectSpace(curCamGroup.Position).X then  
		--Player is to relative right!
	
		
		local WorldPosA = curCamGroup.CFrame:PointToWorldSpace(Vector3.new(posA.X, 0,0))
		local WorldPosB = script.Parent.Cam3.CFrame:PointToWorldSpace(Vector3.new(script.Parent.Cam3.CFrame:PointToObjectSpace(player.Character.HumanoidRootPart.Position).X, 0,0))
		

		
		local newCFrame = CFrame.lookAt(WorldPosA,WorldPosB) * CFrame.Angles(0,math.rad(90),0)
		local newWorldPos = newCFrame:PointToWorldSpace(Vector3.new(newCFrame:PointToObjectSpace(player.Character.HumanoidRootPart.Position).X,0,0))
		
		midCamPart.CFrame = newCFrame
		midCamPart.Position = newWorldPos
		camPart.CFrame = CFrame.lookAt(WorldPosA,player.Character.HumanoidRootPart.Position)
		dupCamPart.CFrame = CFrame.lookAt(WorldPosB,player.Character.HumanoidRootPart.Position)
	else
		--Player is to relative left!
	end
end
1 Like