How can I make scriptable camera like default?

I decided to make camera type to scriptable because of few reasons, it was good but scriptable camera’s couldn’t move it’s rotation or something. So I’m trying to script it so it can turn like default camera type setting.
To make that, I need to detect mouse move with RMB(turning camera) and mouse move with shift lock.
How can I detect those acts and make camera turn?

use cframe, cframe is controlling both position and rotation. which is, very useful

I need to detect mouse move(RMB + mouse move) and shift lock + mouse move
How can I detect those?

There is an example script under get mouse delta.

https://developer.roblox.com/en-us/api-reference/function/UserInputService/GetMouseDelta

uhh delta is always 0, 0 in status of Scriptable camera type, is there any way to fix this?

Right in the article I linked

This function only works if the mouse has been locked using the UserInputService.MouseBehavior property.

I made it but only Y axis gets weird even X and Z axis works.
when I move mouse left and right, It goes left and right but it cannot go further.
https://gyazo.com/3712296d1bb6ed3261212abd4fe9fd82

while true do
	local mouseDelta = UserInput:GetMouseDelta()
	if mouseDelta ~= Vector2.new(0, 0) then
		local pastAngleX, pastAngleY, pastAngleZ = workspace.CurrentCamera.CFrame:ToEulerAnglesXYZ()
		local angle = CFrame.fromOrientation(pastAngleX + math.rad(mouseDelta.Y), pastAngleY + math.rad(mouseDelta.X), math.rad(0))
		workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position) * angle
	end
	game:GetService("RunService").RenderStepped:wait()
end

Remember that EulerAngleXYZ does not equal orientation. Use CFrame:ToOrientation() instead.

Other than that it should be good to go with an additional mouse button 2 to lock the mouse.


local UserInput = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

game:GetService("RunService").RenderStepped:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable

	local mouseDelta = UserInput:GetMouseDelta()
	if mouseDelta ~= Vector2.new(0, 0) then
		local pastAngleX, pastAngleY, pastAngleZ = camera.CFrame:ToOrientation()
		local angle = CFrame.fromOrientation(pastAngleX + math.rad(mouseDelta.Y), pastAngleY + math.rad(mouseDelta.X), math.rad(0))
		camera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position) * angle
	end
end)

local ContextActionService = game:GetService("ContextActionService")

local function handleAction(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		UserInput.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition		
	elseif inputState == Enum.UserInputState.End then
		UserInput.MouseBehavior = Enum.MouseBehavior.Default		
	end
end

ContextActionService:BindAction("LockCamera",handleAction,false,Enum.UserInputType.MouseButton2)
1 Like