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