I’m currently working on a boxing game camera, similar to EA’s UFC Boxing, and I want the camera to rotate with the player and enemy.
I’ve gotten close, with the camera following the point between both players, but the camera ends up rotating on its axis rather than rotating based on the midpoint of both players.
Video: https://i.gyazo.com/de4ff9d1b6d888a870b1f736da2b9a90.mp4
I’ve tried a few possible solutions, but I’m pretty new to camera manipulation and CFrames and couldn’t get it working well enough.
Here’s my camera code so far:
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local cameraOffset = Vector3.new(0, 1.5, 15)
local player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local folder = ReplicatedStorage:WaitForChild("FightingEvents")
local AddGyro = folder:WaitForChild("AddGyro")
local RotatePlayer = folder:WaitForChild("RotatePlayer")
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
humanoid.AutoRotate = false
AddGyro:FireServer()
local enemy = game.Workspace:WaitForChild("Enemy")
local enemyRootPart = enemy:WaitForChild("HumanoidRootPart")
camera.FieldOfView = 55
RunService.RenderStepped:Connect(function()
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
end
RotatePlayer:FireServer(enemy)
camera.CFrame = CFrame.new((rootPart.Position + enemyRootPart.Position)/2+ cameraOffset) * CFrame.Angles(0, (math.rad(character.HumanoidRootPart.Orientation.Y)+1.5), 0)
end)
end)
local function focusControl(actionName, inputState, inputObject)
-- Lock and hide mouse icon on input began
if inputState == Enum.UserInputState.Begin then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false
ContextActionService:UnbindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
end
end
ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
Any help would be appreciated!