I’m trying to make a top-down camera that is over the player but moves in the direction of the mouse. However, it seems like the X and Y positions are swapped. Is there any way to fix this?
local downCameraCf =CFrame.Angles(math.rad(-90),0,0)
threshold = 5
runService.RenderStepped:Connect(function(dt)
if character then
local mousep = mouse.Hit.p
local targetPos = (rootpart.Position +mousep) / 2;
local x = math.clamp(targetPos.X, -threshold + rootpart.Position.X, threshold + rootpart.Position.X)
local z = math.clamp(targetPos.Z, -threshold + rootpart.Position.Z, threshold + rootpart.Position.Z)
targetPos = CFrame.new(x,rootpart.Position.Y,z)
camera.CFrame = targetPos*downCameraCf+Vector3.new(0,25,0)
end
end)
this is the visual example of what’s happening:
https://gyazo.com/b7f7a4f0102c509d805b29d233088e57
Edit: video format if the link isn’t working