UFC Type/Combat camera system

I’m trying to make a combat like camera system similar to UFC 4:

I currently have it so that the camera will go to a middle point in-between my 2 characters:

My problem is that the rotation of the camera does not stay relative to the 2 characters, only the position, and I am not sure how to fix this

Here is my code:

local DistanceFactor = 12.5

function CameraStep()
	local Distance = (RedPart.Position - BluePart.Position).Magnitude
	DistanceFactor = math.clamp(Distance / 3, 8, 20)

	local OriginalGoal = RedPart.Position:Lerp(BluePart.Position, 0.5)
	local Goal = CFrame.new(OriginalGoal) * CFrame.new(-DistanceFactor, DistanceFactor, DistanceFactor)
	Goal = CFrame.new(Goal.Position, OriginalGoal)
	Camera.CFrame = Goal
end

RunService:BindToRenderStep("CameraRunner", 1, CameraStep)

If anyone has any ideas on how to fix this or any advice it would be very much appreciated!

Thanks :smiley:

I’ve never played UFC so I don’t know if it’s coincidental but in that clip it seems like the camera is locked to an arc about the cage. I’m guessing the player controls it left/right. Could you do the same? Lock it on a radius from the center of the ring, and have it face that point center of the two players?

1 Like

Yeah you’re right it seems like its locked on the cage, not sure how to lock it on the radius but I’ll try and figure it out, thanks for the idea!

Here’s an example I wrote and tested out, I got movement similar to that clip. I assumed A/D controls and the ring has a radius of 10 studs.

local cam = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")

cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(Vector3.new(0, 4, 10), Vector3.new(0, 4, 0))

local rotation = 0
local offset = Vector3.new(0, 4, 10) --the offset the camera is from the center 

local turnSpeed = 1/8 --how quickly to turn
local angleInterval = 5 --how far to turn every turnSpeed, the larger the number, the less circular the movement will look
local info = TweenInfo.new(turnSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

UIS.InputBegan:connect(function(input)
	--cam.CameraType = Enum.CameraType.Scriptable
	if (input.UserInputType ~= Enum.UserInputType.Keyboard) or ((input.KeyCode ~= Enum.KeyCode.A) and (input.KeyCode ~= Enum.KeyCode.D)) then return end
	--print(string.format("Going %s", input.KeyCode == Enum.KeyCode.A and "Left" or "Right"))
	
	repeat
		rotation = math.clamp(rotation + (input.KeyCode == Enum.KeyCode.A and -angleInterval or angleInterval), -90, 90)
		local target = CFrame.new(0, 4, 0) * CFrame.Angles(0, math.rad(rotation), 0) --you would want to change this CFrame.new to your mid position
		TS:Create(cam, info, {CFrame = target:ToWorldSpace(CFrame.new(offset))}):Play()
		task.wait(turnSpeed)
	until (not UIS:IsKeyDown(input.KeyCode)) or math.abs(rotation)==90 --quit if key is released *or* the max is hit
end)

You would be changing the CFrame it’s focusing on, where I did CFrame.new(0, 4, 0), to where the center of the two people is at

Appreciate it a lot!!! Going to try and get this working now! :smiley:

1 Like