How to know where the thumbstick is pointed at using User Input Service?


#1

Now before I start, I just want to let you know that there is a solution for this by madattak. I just want to see if there is a better way.

I am currently modifying AxisAngle’s skydiving script and trying to make it mobile compatible. Here is the piece of the code that requires the key codes:

function KeyPressed(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		Key = input.KeyCode
		if Key == Enum.KeyCode.D or Key == Enum.KeyCode.DPadRight then
			TwistConvergence = 1.2
		end
		if Key == Enum.KeyCode.A or Key == Enum.KeyCode.DPadLeft then
			TwistConvergence = -1.2
		end
		if Key == Enum.KeyCode.W or Key == Enum.KeyCode.DPadUp then
			TiltConvergence = 1
		end
		if Key == Enum.KeyCode.S or Key == Enum.KeyCode.Down then
			TiltConvergence = -1	
		end
	end
end

function KeyUnpressed(input)
	if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Touch then
		Key = input.KeyCode
		if Key == Enum.KeyCode.D or Key == Enum.KeyCode.A or Key == Enum.KeyCode.DPadLeft or Enum.KeyCode.DPadRight then
			TwistConvergence = 0
		end
		if Key == Enum.KeyCode.W or Key == Enum.KeyCode.S or Key == Enum.KeyCode.DPadUp or Enum.KeyCode.DPadDown then
			TiltConvergence = 0
		end
	end
end

What I want to do is to replace those “DPad” things with Thumbstick ones. By the way, the DPad does not work either, for some reason.

Is there a better way than madattak’s? All help is appreciated!


#2

Jeeze they don’t make it easy to find, but there is indeed a better way.

local MasterControl = require(player:WaitForChild(“PlayerScripts”):WaitForChild(“ControlScript”):WaitForChild(“MasterControl”))
local MoveVector = MasterControl:GetMoveVector()
if MoveVector.Magnitude>1 then
MoveVector = MoveVector.unit
end

Edit: Woops, just spent a while digging this up and then realised @Maelstronomer had posted this solution in that same thread XD
https://devforum.roblox.com/t/how-do-you-make-a-script-respond-to-the-mobile-thumbstick/33906/8?u=madattak


#3

Thank you so much! It is really a lot easier to use!