My goal is to create a 2D camera where it adjusts if the person moves away or towards the camera.
A group of friends and I are hoping to achieve some sort of Tekken-like game, and I have ran into an issue, I’ve obtained a great camera system for a 2D gameplay fighter, but the issue is the mid point does not adjust itself like Tekken, where if the person moves onto the z-axis, the camera stays stuck on its current axis and does not correct itself, basically removing the illusion of the 2D camera, and this just makes the game unplayable.
I’ve tried AlignOrientations in a separate baseplate, with no luck.
I’ve attempted to use :ToObjectSpace(), but I have no idea to implement that.
I am just stuck, and I hope some mythical CFrame wizard can help me.
Script: Source
local player1 = game.Workspace.engineInfo.player1Obj.Value
local player2 = game.Workspace.engineInfo.player2Obj.Value
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local fov = workspace.CurrentCamera.FieldOfView
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(dt)
if player1.Character and player1.Character:FindFirstChild("HumanoidRootPart") then
local distance = (player1.Character.HumanoidRootPart.Position - player2.Character.HumanoidRootPart.Position).Magnitude
local length = (distance/2)/math.tan(fov/2)
local center = player1.Character.HumanoidRootPart.Position:Lerp(player2.Character.HumanoidRootPart.Position, 0.5)
local offset = Vector3.new(0, 0, length)
local goalCF = CFrame.new(center + offset, center) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(goalCF,0.05)
end
end)