How to tell when player is holding thumbstick in certain direction

I want to know if a player is holding their thumbstick left or right, without using player movement as a basis (character doesn’t exist in use case)

The delta will eventually return to 0, even though my thumbstick is to the right or left still, so I need to know when they currently have it left or right

game:GetService("UserInputService").InputChanged:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Thumbstick1 then
		print(input.Delta.X)
	end
end)

Replace input.Delta with input.Position. Delta is just the difference from the current frame and the last frame.

2 Likes

Just like @bluebxrrybot said, you have to use InputObject.Position. The problem was that you were using InputObject.Delta, which basically tracks the changes in position between the previous frame and the current one. This is useful sometimes, but probably not in your case.

Here is some demo code that you can use as a reference for what you want to do:

-- Services --

local UserInputService = game:GetService("UserInputService")

-- Scripting --

UserInputService.InputChanged:Connect(function(Input, GameProcessed) 	-- Thumbstick positions can only be retrieved by the "InputChanged" function, "InputBegan" does not work
	if Input.UserInputType == Enum.UserInputType.Gamepad1 then			-- Make sure that it is a controller (in this case, the first one connected)
		if Input.KeyCode == Enum.KeyCode.Thumbstick1 then				-- Currently checking only the right thumbstick
			local PositionX = Input.Position.X							-- Retrieve X-Axis position (-1 is far left and 1 is far right)
			local PositionY = Input.Position.Y							-- Retrieve Y-Axis position (-1 is far down and 1 is far up)
			
			print("X: "..PositionX)
			print("Y: "..PositionY)
			
			print("\n")
		end
	end
end)

Hopefully this helped.

1 Like

Here you go.

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

if UserInputService.TouchEnabled then
	local TouchGui = PlayerGui:WaitForChild("TouchGui")
	local TouchControlFrame = TouchGui:WaitForChild("TouchControlFrame")
	local DynamicThumbstickFrame = TouchControlFrame:WaitForChild("DynamicThumbstickFrame")

	local function OnInputBegan(Input, Processed)
		if Processed then return end
		
		if Input.UserInputType == Enum.UserInputType.Touch then
			local Position = Input.Position
			local FramePosition = DynamicThumbstickFrame.AbsolutePosition
			local FrameSize = DynamicThumbstickFrame.AbsoluteSize
			if Position.X > FramePosition.X and Position.X < FramePosition.X + FrameSize.X and Position.Y > FramePosition.Y and Position.Y < FramePosition.Y + FrameSize.Y then
				print("Dynamic thumbstick used!")
			else
				print("Dynamic thumbstick not used!")
			end
		end
	end

	UserInputService.InputBegan:Connect(OnInputBegan)
end