I’m setting up xbox controls on my game and I need to know how to detect if a thumbstick is being angled with someone’s thumb. I didn’t know how to set this up in a simple way so I looked at another developer’s code and pasted it into a local script to experiment with.
local UserInputService = game:GetService("UserInputService")
local function OnInputChanged(Input, GameProcessedEvent)
while wait(10) do
if Input.KeyCode == Enum.KeyCode.Thumbstick1 then
--print("Thumbstick 1")
if Input.Delta.X >= 0.1 then
print("LEFTStickWentRight")
elseif Input.Delta.X <= 0.1 then
print("LEFTStickWentLeft")
elseif Input.Delta.Y >=0.1 then
print("LEFTStickWentUp")
elseif Input.Delta.Y <= 0.1 then
print("LEFTStickWentDown")
end
--elseif Input.KeyCode == Enum.KeyCode.Thumbstick2 then
--print("Thumbstick 2")
--if Input.Delta.X > 0 then
--print("Right")
--elseif Input.Delta.X < 0 then
--print("Left")
--end
end
end
end
UserInputService.InputChanged:Connect(OnInputChanged)
I doubt if I’m even doing the naming correctly, but this is what the output gave me.
It was really laggy when I opened it up. The left thumbstick was detected but not in the manner I wanted. I want the text “LEFTStickWentRight” to be printed if I move the thumbstick right and “LEFTStickWentLeft” if I move it left. Same thing up and down. But the inputs seemed like it didn’t matter in the output.