So, I am making a dynamic top down camera (Where camera moves according to your mouse position) and I think I am close to achieving it but The camera is showing weird behaviour
(I recorded a video but my pc is so trash it’s literally at 1 fps so you can check it out at the place below)
Here’s the script
--Made by Beastcraft_Gaming
--Variables--
local player: Player = game.Players.LocalPlayer;
local character: Model = player.Character or player.CharacterAdded:Wait();
local humPart = character:WaitForChild("HumanoidRootPart");
local head = character:WaitForChild("Head");
local mouse = player:GetMouse();
local mousePosition
local camera = workspace.CurrentCamera;
local camHeight = script:GetAttribute("Cam_Height");
local maxDist
--Main
camera.CameraType = Enum.CameraType.Scriptable;
--camera.CameraSubject = humPart;
while true do
camHeight = script:GetAttribute("Cam_Height");
maxDist = script:GetAttribute("Max_Dist");
mousePosition = mouse.Hit;
--distance between character and mouse
local dist = (head.Position - mousePosition.Position).Magnitude;
--clamping the dist
dist = math.clamp(dist, 0, maxDist);
--Offset vector
local x = mousePosition.Position.Unit.X * dist ;
local z = mousePosition.Position.Unit.Z * dist ;
local OffsetVector = Vector3.new(x, camHeight, z);
camera.CFrame = CFrame.new(head.Position + OffsetVector);
camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(-90),0,0);
game:GetService("RunService").Heartbeat:Wait();
end