:IsKeyDown() On Mobile

Hello, how would I know if a player on mobile is going right/left/forward/backward on mobile? I could use humanoid move direction or rootpart cframe, but I want to use inputs instead for a more accurate input.
Thank you.

You can use PlayerActions with BindAction, like:

local CAS = game:GetService("ContextActionService")
local function Function(Name: string, State: Enum.UserInputState, Input: InputObject)
	print(Name, State)
end
CAS:BindAction("CharacterLeft", Function, false, Enum.PlayerActions.CharacterLeft)
CAS:BindAction("CharacterRight", Function, false, Enum.PlayerActions.CharacterRight)
CAS:BindAction("CharacterForward", Function, false, Enum.PlayerActions.CharacterForward)
CAS:BindAction("CharacterBackward", Function, false, Enum.PlayerActions.CharacterBackward)

I think it can be made more compact, but this is the idea.

1 Like

MoveDirection is as close as you’ll get, unless you want to do some tedious ContextActionService work that adds initialization lines to your functions.

1 Like

Is this the same thing as :KeyDown?

Yes and no, because it won’t fully work on mobile. It will not work with joysticks but will work with the thumbpad.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.