Does anyone know how to fix this issue: Basically im trying to make a camera like tekken/street fighter (2d fighting camera) which has all players in frame and moves when the player moves. But whenever i move or another person moves the camera just stays in place.
Example:
script:
local cam = workspace.CurrentCamera
local Players = game:GetService("Players")
local xoffset = 0
local yoffset = 2
local zoffset = 10
local hrpArray = {}
for _, player in Players:GetPlayers() do
task.spawn(function()
local character = player.Character or player.CharacterAdded:Wait()
hrpArray[player] = character:WaitForChild("HumanoidRootPart")
end)
end
Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
hrpArray[player] = character:WaitForChild("HumanoidRootPart")
end)
Players.PlayerRemoving:Connect(function(player)
hrpArray[player] = nil
end)
print(hrpArray)
local camPart = Instance.new("Part")
camPart.Anchored = true
camPart.Name = "CamPart"
camPart.Parent = workspace
function calculateAveragePosition()
local total = Vector3.new()
for _, humrootpart in pairs(hrpArray) do
total += humrootpart.Position
end
return total / #hrpArray
end
function calculateAverageMagnitude()
local total = 0
for _, humrootpart in pairs(hrpArray) do
total += (humrootpart.Position - camPart.Position).Magnitude
end
return total / #hrpArray
end
wait()
cam.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService").RenderStepped:Connect(function()
local averagePos = calculateAveragePosition()
local averageMagnitude = calculateAverageMagnitude() + zoffset
camPart.Position = averagePos
cam.CFrame = camPart.CFrame * CFrame.new(Vector3.new(xoffset, yoffset, averageMagnitude))
end)