I'm making a custom first person camera script. As apposed to using roblox's so I can add smooth head bobbing, crouching etc. However, I'm bad at 3-D math so I'm stuck on how to make the camera turn with the mouse. What happens is the camera starts twisting and going out of control.
while not game.Players.LocalPlayer.Character do wait() end
local cam = workspace.CurrentCamera
cam.CameraType = "Scriptable"
local plrChar = game.Players.LocalPlayer.Character
local plrHead = plrChar:waitForChild("Head")
plrHead.LocalTransparencyModifier = 1
local CAMERA_MOVE_FACTOR = 3
local xAngle = 0
local yAngle = 0
inputService.InputChanged:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
if input.Delta.x < 0 then
xAngle = xAngle - CAMERA_MOVE_FACTOR
elseif input.Delta.x > 0 then
xAngle = xAngle + CAMERA_MOVE_FACTOR
end
if input.Delta.y < 0 then
yAngle = yAngle - CAMERA_MOVE_FACTOR
elseif input.Delta.y > 0 then
yAngle = yAngle + CAMERA_MOVE_FACTOR
end
end
end)
game:GetService("RunService").RenderStepped:connect(function()
print(CFrame.Angles(math.rad(-yAngle),math.rad(-xAngle),0))
cam.CFrame = CFrame.new(plrHead.CFrame.p) * CFrame.Angles(math.rad(-yAngle),math.rad(-xAngle),0)
end)

2 comments
on 20, 22, 26 and 28, you might want to use multiply instead (eg xAngle * -CAMERA and xAngle *CAMERA)
Okay Ill try it!