How to make a 2d style fighting game camera?

so I have this script that is supposed to have a 2d fighting style camera where its got a camera part, and then the camera will go inward or outward depending on where the 2 players characters are

picture (green brick is camera)

script

local cam = workspace.CurrentCamera

local xoffset = 0
local yoffset = 2
local zoffset = 10

local camPart = game.Workspace.Cameras.C1

function calculateAveragePosition(hcrp1,hcrp2)
	local total = Vector3.new()
	local humrootpart = hcrp1.Position - hcrp2.Position    
		total += #humrootpart.Position
	return total / humrootpart 
end

function calculateAverageMagnitude(hcrp1,hcrp2)
	local total = 0
	local humrootpart = hcrp1.Position - hcrp2.Position   
		total += (#humrootpart.Position - camPart.Position).Magnitude

	return total / humrootpart
end

wait()
cam.CameraType = Enum.CameraType.Scriptable

game:GetService("RunService").RenderStepped:Connect(function()
	local hrp1 = game.Players:WaitForChild(script.Parent.Play1.Value).Character:WaitForChild("HumanoidRootPart")
	local hrp2 = game.Players:WaitForChild(script.Parent.Play2.Value).Character:WaitForChild("HumanoidRootPart")
	local averagePos = calculateAveragePosition(hrp1,hrp2)
	local averageMagnitude = calculateAverageMagnitude(hrp1,hrp2) + zoffset

	camPart.Position = averagePos
	cam.CFrame = camPart.CFrame * CFrame.new(Vector3.new(xoffset, yoffset, averageMagnitude))
end)

I cant seem to get the camera to be on the part but still move in and out with the players

2 Likes

Can someone answer this, im experiencing the same issue.

1 Like

In Create new within roblox studio, there is a game called Line Runner. Within there is a script that lets u manipulate the camera to have a 2d effect. Maybe u could use that