Cross-platform keybinding and how to know current platform (Mobile PC Console)

Just wondering about proper methodologies for accomplishing keybinding for any platform, I have sample code that I havent fully tested but from delving into forum posts this seems to be the answer

One thing that seems ambiguous is determining what platform localplayer is currently on

--for console and pc
ContextActionService:BindAction("CheckActiveWASD", CheckActiveWASD, false,
		Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Thumbstick1)
	
	
	--Mobile
	game.RunService.Stepped:Connect(function()
		
		if humanoid.MoveDirection.X > 0 then 
			--D
		elseif humanoid.MoveDirection.X < 0 then
			--A
		
		end

		if humanoid.MoveDirection.Z > 0 then 
			--W
		elseif humanoid.MoveDirection.Z < 0 then
			--S
		
		end

		

	end)

I don’t know why but this sort of thing seems ambiguous, mysterious, unknown and different solutions seem to exist??? from what i’ve read, thumbstick1 doesnt work for mobile so a user suggested to use the vector from humanoid :person_shrugging:

this seems to be a better method for mobile

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local ControlModule = require(LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"):WaitForChild("ControlModule"))

while true  do
	task.wait()
	local currentDirection = ControlModule:GetMoveVector()
	print(currentDirection)
end

Don’t base it on platform, base it off of InputType. Players can play on a laptop that has touchscreen or play on a phone with a Bluetooth controller.

Here’s my code on how to distinguish InputType. I also mention some issue with said code/implementation:

1 Like

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