I wanted to achieve a first-person like camera system. I cannot use the regular camera, because of other systems I have in the game. The camera can move vertically, but the HumanoidRootPart has to rotate in order for the camera to move horizontally.
In a normal game, you can turn your camera to the side in an unlimited way. However the camera is limited even though I have not set a limit for it.
The issue might be in the line of code where it adds MouseDelta.X, but I couldn’t figure out how to fix it.
local localCf = CFrame.identity
local bounds = math.rad(90)
local offset = Vector3.new(0, 1, 0)
--Putting this in breaks it more
local function correctionLocalCf()
local x, y, z = localCf:ToEulerAnglesXYZ()
localCf = CFrame.Angles(x, y, 0)
end
Camera.CameraType = Enum.CameraType.Scriptable
RunService:BindToRenderStep("AttachCamera", Enum.RenderPriority.Camera.Value - 1, function()
local mouseDelta = -InputService:GetMouseDelta() * math.rad(InputService.MouseDeltaSensitivity / 8)
InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, previousYaw, _ = localCf:ToEulerAnglesXYZ()
localCf *= CFrame.Angles(mouseDelta.Y, 0, 0) --= CFrame.Angles(math.clamp(pitch + mouseDelta.Y, -bounds, bounds), yaw + mouseDelta.X, 0)
--correctionLocalCf()
--local pitch, yaw, _ = localCf:ToEulerAnglesXYZ()
--localCf = CFrame.Angles(math.clamp(pitch + mouseDelta.Y, -bounds, bounds), yaw + mouseDelta.X, 0)
local grounded = HumanoidRootPart:GetAttribute("Grounded")
local pitch, yaw, _ = localCf:ToEulerAnglesXYZ()
if previousYaw ~= yaw then
print(previousYaw, yaw)
end
local x, y, z = HumanoidRootPart.CFrame:ToEulerAnglesXYZ()
local toDeg
HumanoidRootPart.CFrame =
CFrame.new(HumanoidRootPart.CFrame.Position) *
CFrame.Angles(grounded and 0 or x, y + mouseDelta.X, grounded and 0 or z)
print(y + mouseDelta.X)
local finalCf = Head.CFrame:ToWorldSpace(localCf)
--[[
if grounded then
local x, y, _ = finalCf:ToEulerAnglesXYZ()
finalCf = CFrame.new(finalCf.Position) * CFrame.Angles(x,y, 0)
end]]
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = finalCf --Head.CFrame:ToWorldSpace(localCf)
end)