Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Added ApplyDeadzone method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Dec 7, 2018
1 parent 49ece02 commit 48cbdf6
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Boolean gamepad:IsMotorSupported(motor)
Boolean gamepad:IsVibrationSupported()
Float gamepad:GetMotorValue(motor)
Float gamepad:ApplyDeadzone(value, deadzoneThreshold)
gamepad.ButtonDown(keyCode)
gamepad.ButtonUp(keyCode)
Expand All @@ -33,6 +34,7 @@ local gamepadsByInputType = {}

local userInput = game:GetService("UserInputService")
local hapticService = game:GetService("HapticService")
local abs = math.abs


function Gamepad.new(gamepad)
Expand Down Expand Up @@ -169,6 +171,17 @@ function Gamepad:StopAllMotors()
end


function Gamepad:ApplyDeadzone(value, deadzoneThreshold)
if (abs(value) < deadzoneThreshold) then
return 0
elseif (value > 0) then
return ((value - deadzoneThreshold) / (1 - deadzoneThreshold))
else
return ((value + deadzoneThreshold) / (1 - deadzoneThreshold))
end
end


function Gamepad:Start()

end
Expand All @@ -179,4 +192,4 @@ function Gamepad:Init()
end


return Gamepad
return Gamepad

0 comments on commit 48cbdf6

Please sign in to comment.