I want to make my own freecam script, similar to the one in Roblox Studio, and so far I made every part (ASDW movement + mouse wheel movement), except for rotation. I want to make it so when you hold right mouse button your camera rotates just like in Studio camera. I have some knowledge of cframes but my problem is that I dont know how exactly to measure when a player moves the mouse with right mouse button held and how to convert that into camera cframe rotation.
Heres my current code:
local function getSpeed()
if uis:IsKeyDown('LeftShift') or uis:IsKeyDown('RightShift') then
return 0.25
else
return 1
end
end
r:BindToRenderStep("Freecam", 300, function()
local speedFactor = getSpeed()
-- forward/backwards
if uis:IsKeyDown('W') then
camera.CFrame += camera.CFrame.LookVector * speedFactor
elseif uis:IsKeyDown('S') then
camera.CFrame -= camera.CFrame.LookVector * speedFactor
end
-- left/right
if uis:IsKeyDown('A') then
camera.CFrame -= camera.CFrame.RightVector * speedFactor
elseif uis:IsKeyDown('D') then
camera.CFrame += camera.CFrame.RightVector * speedFactor
end
-- up/down
if uis:IsKeyDown('E') then
camera.CFrame += camera.CFrame.UpVector * speedFactor
elseif uis:IsKeyDown('Q') then
camera.CFrame -= camera.CFrame.UpVector * speedFactor
end
end)
So far I’ve tried using UserInputService.InputChanged
to detect when a player moves the mouse around but as I said I dont know how to convert that into cframe rotation:
uis.InputChanged:Connect(function(input, isGameProcessed)
if not isGameProcessed then
if input.UserInputType == Enum.UserInputType.MouseMovement then
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
local pos = input.Position
print('input changed with RMB held:', pos.X,pos.Y)
-- ...how do i convert to cframe rotation?
end
end
end
end)
I didnt found any info on the web. Thanks for any help.