Yeah, the title might be complicated but I’m just wondering if there could be a way to detect if you’re double-tapping a movement of the joystick on an Xbox controller.
The main scenario here is that I am trying to make a sprint system, where Shift is the computer key while double-tapping directions would be for Xbox. This is slightly based off of how Minecraft handles sprinting in their console version.
I’ve tried looking up other stuff but it seems that there’s nothing about this exact topic anywhere.
If anyone can give me some ideas on how to do this exact idea, thanks.
I don’t have much knowledge of gamepad controls but I think something like this should work:
local initPressed = false
local secondPressed = false
local userInputService = game:GetService('UserInputService')
userInputService.InputBegan:Connect(function(key, isSystemReserved)
if not isSystemReserved then
if key.KeyCode == Enum.KeyCode.Thumbstick1 then
local x, y = input.Position.X, input.Position.Y
if x > -0.1 and x < 0.1 and y > 0.9 then -- since I assume x and y aren't always going to be exactly aligned, we want give a little bit of wiggle room.
if not initPressed then
initPressed = true
coroutine.wrap(function()
wait(0.5) -- wait 0.5 seconds for another input
if not secondPressed then
initPressed = false
end
end)()
else
print('User is running')
end
end
end
end
end