How to detect a controller's joysticks' direction

I’m trying to detect the joystick’s direction for UI in my game. Read a few posts about it and tried what was marked as the solutions. Tested it on my Switch pro controller, and it didn’t work.

local function InputFunc(Input,GPE)
	if GPE then
	return end

	print(Input.KeyCode)
	if Input.KeyCode == Enum.KeyCode.Thumbstick1 then
		print("ThumbStick1 Detected")
		print(Input.Position.X,Input.Position.Y)
	end
end

UIS.InputBegan:Connect(InputFunc)
1 Like

Bump… (Does this work?) 30 letters

As far as I know, nintendo controllers don’t work as only xbox and playstation controllers are supported.

Why would they add nintendo input types if that platform doesn’t even have Roblox in their app stores?

1 Like

My nintendo controller works for roblox games, so I don’t see why it wouldn’t work here

It should be InputChanged instead of InputBegan

2 Likes

That absolutely works! Another problem though is that my right thumbstick is drifting like crazy… even when i seem to stop it, it seems to be doing it but just very slowly. Can’t do any other inputs because of it apparently… gotta figure out how to fix that

You can implement a deadzone.

--!strict

local UserInputService = game:GetService("UserInputService")

local DEADZONE: number = 0.1 -- 0-1

UserInputService.InputChanged:Connect(function(input: InputObject, gameProcessedEvent: boolean): ()
	if gameProcessedEvent then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.Thumbstick1 and input.Position.Magnitude > DEADZONE then
		print("InputChanged without drifting")
	end
end)
2 Likes

I should’ve thought of that. Thanks.

Tested it, and it works perfectly now!

OK all of a sudden it just stops reading inputs from my left joystick at all. Any ideas around it, or do you think it’s my controller? Cuz I think it’s the latter.

I can still move around, turn my camera around ingame but I can’t get it to read the inputs.
Of course it still reads from the right joystick though…

Depends on what your code looks like. If you cannot move and you’re merely using InputBegan, then it’s probably your controller if there is no other code interference.

I’m using InputChanged.

local function InputFunc(Input,GPE)
	if GPE then
	return end

	local DEADZONE = 0.1
	
	if Input.KeyCode == Enum.KeyCode.Thumbstick1 then
		print(Input.Position.X,Input.Position.Y,Input.KeyCode)
	elseif Input.KeyCode == Enum.KeyCode.Thumbstick2 and Input.Position.Magnitude > DEADZONE then
		print(Input.Position.X,Input.Position.Y,Input.KeyCode)
	end
end

UIS.InputChanged:Connect(InputFunc)

I tried checking if the left thumbstick somehow couldn’t get past the deadzone, but no it just doesn’t input whatsoever. Probably the controller, I’ll try recalibrating it soon.

Funnily enough, I also test all my gamepad code with a Switch Controller. Since it is not natively supported on Windows, I use BetterJoy as my controller drivers. Although very buggy, if you are using custom drivers, try running it on Administrator mode and see if that helps.

1 Like

I just had a realization. Potentially its steam. I remember setting my joystick inputs to W,A,S, and D a few months back. I’ll check if its that.


what the hell? how does that even happen lol

context: the controller is making tons of inputs on its own as soon as i disabled steam input…

Unfortunately this is just issues with Windows and/or the drivers themselves, not a Roblox issue, so this thread should remain closed. Feel free to DM me details and I might be able to help.

1 Like

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