Stopping player from rotating camera without setting it to scriptable?

(Before anyone mentions it, I have searched numerous devforum posts already, no solution was found for this specific issue)

I am attempting to make a Top-down camera, issue is that rotating the camera causes issues and I don’t really even want it to be a thing either
I set it to scriptable but that removes the ability to zoom in and out, which I need. I tried making my own code for zooming in and out but it didn’t work properly.

Appreciate any help

At first I was thinking of ideas and tested a few things out and thought It was impossible. I thought of ways to block or override the input but nothing would work nicely. So I came up with this which causes a continuous adjustment of the camera’s CFrame, effectively neutralizing any rotation caused by mouse movement while not making it scriptable.


local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local userInputService = game:GetService("UserInputService")


-- Function to handle input
local function handleInput(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		return Enum.ContextActionPriority.High.Value
	end
end

-- Bind the function to ContextActionService
game:GetService("ContextActionService"):BindAction("DisableRotationInputs", handleInput, false,
	Enum.UserInputType.MouseMovement
)

-- Toggle rotation on right mouse button
local isRotating = false

-- Function to toggle camera rotation
local function toggleRotation(actionName, inputState, input)
	if inputState == Enum.UserInputState.Begin then
		isRotating = true
	elseif inputState == Enum.UserInputState.End then
		isRotating = false
	end
end

-- Bind the function to ContextActionService
game:GetService("ContextActionService"):BindAction("ToggleCameraRotation", toggleRotation, false, Enum.UserInputType.MouseButton2)

-- Connect the function to RenderStepped
game:GetService("RunService").RenderStepped:Connect(function()
	if isRotating then
		-- Adjust the camera's CFrame based on mouse input (disable rotation)
		camera.CFrame = CFrame.new(camera.CFrame.Position)
	end
end)

-- Optional: Show the mouse cursor
userInputService.MouseIconEnabled = true

1 Like

I really appreciate it, I was genuinely so lost on what to do. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.