Hi,
I’m trying to make a custom camera script where you can look around using your mouse.
UIS.InputChanged:Connect(function(input)
if (lastMousePos and input.UserInputType == Enum.UserInputType.MouseMovement) then
local pos = UIS:GetMouseLocation()
local yDiff, xDiff = lastMousePos.Y - pos.Y, lastMousePos.X - pos.X
camera.CFrame *= CFrame.Angles(math.rad(yDiff / 3), math.rad(xDiff / 3), 0)
lastMousePos = pos
end
end)
This is what I made but it also moves the camera crosswise which looks weird.
https://gyazo.com/20d58b4fe2d5589604202cc9672c3318
I tried to zero out the Z axis every time the CFrame changes.
It’s a bit better but still makes the camera do some weird rotation.
https://gyazo.com/357e66c2160e5dfd328769397b27504a
local function RemoveZRotation(cframe)
local x, y, z = cframe:ToOrientation()
return CFrame.new(cframe.Position) * CFrame.Angles(x,y,0)
end
UIS.InputChanged:Connect(function(input)
if (lastMousePos and input.UserInputType == Enum.UserInputType.MouseMovement) then
local pos = UIS:GetMouseLocation()
local yDiff, xDiff = lastMousePos.Y - pos.Y, lastMousePos.X - pos.X
local newRot = camera.CFrame * CFrame.Angles(math.rad(yDiff / 3), math.rad(xDiff / 3), 0)
camera.CFrame = RemoveZRotation(newRot)
lastMousePos = pos
end
end)
Could I get some help, please?