Moving the camera with Character's X and Z while focusing a part

I am trying to create movement around a part but when I spam A and D it distances me further away from the center for some reason
Here’s a clip of it in a different game:
https://youtu.be/8gekoT5Amx8?t=75
Clip of the issue:
https://streamable.com/f6fwhr

local Camera = game.Workspace.CurrentCamera
local Part = game.Workspace:WaitForChild("Part")
local RunService = game:GetService("RunService")

local ContextActionService = game:GetService("ContextActionService")
local ForwardMovement = Enum.PlayerActions.CharacterForward
local BackwardMovement = Enum.PlayerActions.CharacterBackward

local function Sink()
	return Enum.ContextActionResult.Sink
end

local FocusLoop

game.ReplicatedStorage.FocusMalakai.OnClientEvent:Connect(function(State)
	if State then
		FocusLoop = RunService.RenderStepped:Connect(function()
			Camera.CFrame = CFrame.new(Vector3.new(Camera.CFrame.X, Part.Position.Y + 9, Camera.CFrame.Z), Part.Position) -- my method used to set the camera
		end)
		ContextActionService:BindAction("SinkForwardMovement", Sink, false, ForwardMovement)
		ContextActionService:BindAction("SinkBackwardMovement", Sink, false, BackwardMovement)
	else
		if FocusLoop then
			FocusLoop:Disconnect()
			FocusLoop = nil
		end
		ContextActionService:UnbindAction("SinkForwardMovement")
		ContextActionService:UnbindAction("SinkBackwardMovement")
	end
end)

You might need to set a fixed distance instead of updating the camera’s CFrame based on its current CFrame.

1 Like

hmm what do you mean?‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍