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

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!

1 Like

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

local MasterControl = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"):WaitForChild("ControlModule"))
local MoveVector = MasterControl:GetMoveVector()
if MoveVector.Magnitude>1 then
	MoveVector = MoveVector.Unit
end

Edit: Updated for Anthro!

17 Likes

Bumping this because if you used the previous solution, you will need to update it! Anthro changed the name of the control script in the character. I’ve fixed it in my post.

1 Like