UserInputService.InputChanged event doesn't register MouseButton1?

UserInputService = game:GetService("UserInputService")
UserInputService.InputChanged:Connect(function(inputObj)
	print(inputObj.UserInputType)
	if (inputObj.UserInputType == Enum.UserInputType.Touch) or (inputObj.UserInputType == Enum.UserInputType.MouseButton2) then
		print('changed! ',inputObj)
	end
end)

Works with mobile touch, but not with a mouse.
Is this expected?

(Use mobile emulator to test image)

I’m working on custom camera panning, and this makes things more difficult.

Click here if you want to see the full script I’m working on instead of the abstracted section.

Just use:
local Players = game:GetService(“Players”)
local localPlayer = Players.LocalPlayer

local mouse = localPlayer:GetMouse()
mouse.Button1Down:Connect(function()
–YOUR CODE HERE
end)

1 Like

Also, you used Button2 instead of button 1 you do know that button 2 is the RMB right?

@YellowBannana898 I’m not trying to detect mouse click, I’m trying to detect mouse-click-and-drag.
Also, yes, I know MouseButton2 is right mouse button.

@sizquirt The emulator works fine. You just have to click here.


image

My problem is that UserInputService.InputChanged doesn’t register MouseButton1 click movement like it does touch click movement.

Read this You might need to use cameratype.Scripted

My camera type is already set to scriptable, but this has nothing to do with cameras.
Here’s my full camera script. I’m working on panning for my game’s orthographic camera.

-- ToldFable 2022

local CameraCircleAngleRad = 0
local panHeight = 0
local cameraMagnitude = 2000--2500

local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = nil
Camera.FieldOfView = 0

local lookingAtPos = Vector3.new(0,-80,0)


function Pan(inputObj)
	local oldPosition = inputObj.Position - inputObj.Delta
	--print(touch.Delta.Y)
	--print("Touch moved from " .. tostring(oldPosition) .. "to " .. tostring(touch.Position))
	CameraCircleAngleRad += (inputObj.Delta.X/200)
	--panHeight += (touch.Position.Y/20)
	panHeight += inputObj.Delta.Y*10
end

UserInputService.InputChanged:Connect(function(inputObj)
	if inputObj.UserInputType == Enum.UserInputType.Touch then
		--or	inputObj.UserInputType == Enum.UserInputType.MouseButton1 then -- weird behavior
		print('changed')
		Pan(inputObj)
	end
end)

while true do
	wait()
	local cameraOrigin = Vector3.new((math.cos(CameraCircleAngleRad)*cameraMagnitude),2000,(math.sin(CameraCircleAngleRad)*cameraMagnitude))
	Camera.CFrame = CFrame.new(cameraOrigin,lookingAtPos+Vector3.new(0,(cameraMagnitude/2500)*100*panHeight/3000,0))
	--CameraCircleAngleRad += 0.01
end

Reccomended steps if you’re going to run this:

  • Add a map into workspace
  • Disable Player.CharacterAutoLoads
  • Enable mobile emulation

I think this is just unexpected behavior.

This is how I ended up solving this:

-- ToldFable 2022

local CameraCircleAngleRad = 0
local panHeight = 0
local cameraMagnitude = 2000--2500

local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = nil
Camera.FieldOfView = 0

local lookingAtPos = Vector3.new(0,-80,0)

function Pan(inputObj)
	--local oldPosition = inputObj.Position - inputObj.Delta
	--print(touch.Delta.Y)
	--print("Touch moved from " .. tostring(oldPosition) .. "to " .. tostring(touch.Position))
	CameraCircleAngleRad += (inputObj.Delta.X/200)
	--panHeight += (touch.Position.Y/20)
	panHeight += inputObj.Delta.Y*10
end

local lastMousePos = UserInputService:GetMouseLocation()

UserInputService.InputChanged:Connect(function(inputObj)
	if inputObj.UserInputType == Enum.UserInputType.Touch then
		--or	inputObj.UserInputType == Enum.UserInputType.MouseButton1 then -- weird behavior
		print('changed')
		Pan(inputObj)
	elseif UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
		print'button pressed'
		--print(inputObj.Delta)
		--Pan(inputObj)
		Pan({
			Delta = UserInputService:GetMouseLocation() - lastMousePos
		})
		lastMousePos = UserInputService:GetMouseLocation()
	else
		lastMousePos = UserInputService:GetMouseLocation()
	end
end)

while true do
	wait()
	local cameraOrigin = Vector3.new((math.cos(CameraCircleAngleRad)*cameraMagnitude),2000,(math.sin(CameraCircleAngleRad)*cameraMagnitude))
	Camera.CFrame = CFrame.new(cameraOrigin,lookingAtPos+Vector3.new(0,(cameraMagnitude/2500)*100*panHeight/3000,0))
	--CameraCircleAngleRad += 0.01
end

My code continues to devolve! :stuck_out_tongue:

There’s probably a better way to do this that I’m unaware of, but the behavior in the OP doesn’t make intuitive sense IMO. Seems like a UX bug.