im remaking roblox’s camera system so i can branch off it
but im having an issue with the y position / angle
local camDist = 5
local cX, cY = 0, 0
self.renderLoop = RunService.RenderStepped:Connect(function(dt)
local mouseDelta = UserInputService:GetMouseDelta()
local transformedMouseDelta = Vector2.zero
if (rmbHeld and mouseDelta.Magnitude ~= 0) then
transformedMouseDelta = getDelta(mouseDelta, dt)
cX = (cX + transformedMouseDelta.X) % 360
cY = math.clamp(cY + transformedMouseDelta.Y, -89, 89)
end
local cXrad = math.rad(cX)
local cYrad = math.rad(cY)
local position = CFrame.new(humanoidRootPart.CFrame.Position) * CFrame.new(camDist * math.sin(cXrad), camDist * -cYrad, camDist * math.cos(cXrad))
-- (line above) y position not right?
local angle = CFrame.fromEulerAnglesXYZ(0, cXrad, 0)
currentCamera.CFrame = position * angle * CFrame.fromEulerAnglesXYZ(cYrad, 0, 0) -- angle not right?
end)
in the video, the humanoidrootpart needs to be centered in the middle of the camera (by changing either the how the angles calculated or how the y positions calculated), similar to how robloxs camera system behaves. i know for a fact this problem can be solved with a mathematical approach, but i cant figure out how to do so.
(here’s my attempt at an idea, upscaled and cleaned up)
(and im avoiding using CFrame.lookAt because its not necessary)