Custom Character Movement on Mobile using Roblox's Default Controls

  1. What do you want to achieve? Keep it simple and clear!
    I want to integrate my custom character into the mobile controls from Roblox. I override the ControlScript and CameraScript for my game. Here’s my code for on keyboard. I make use of ContextActionService.
local ContextActionService  = game:GetService("ContextActionService")
local player = game:GetService("Players").LocalPlayer

function handleMovement(actionName, inputState, inputObject)
	local character = player.Character or player.CharacterAdded:Wait()
	local vectorForce = character.HumanoidRootPart.VectorForce
	
	if inputState == Enum.UserInputState.Begin then
		if actionName == "Up" then
			vectorForce.Force = Vector3.new(750, vectorForce.Force.Y, vectorForce.Force.Z)
		elseif actionName == "Down" then
			vectorForce.Force = Vector3.new(-750, vectorForce.Force.Y, vectorForce.Force.Z)
		elseif actionName == "Left" then
			vectorForce.Force = Vector3.new(vectorForce.Force.X, vectorForce.Force.Y, -750)
		elseif actionName == "Right" then
			vectorForce.Force = Vector3.new(vectorForce.Force.X, vectorForce.Force.Y, 750)
		end
	elseif inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel then
		local xForce = not (actionName == "Up" or actionName == "Down") and vectorForce.Force.X or 0
		local zForce = not (actionName == "Left" or actionName == "Right") and vectorForce.Force.Z or 0
		vectorForce.Force = Vector3.new(xForce, 0, zForce)
	end
end

ContextActionService:BindAction("Up", handleMovement, false, Enum.KeyCode.W, Enum.KeyCode.Up)
ContextActionService:BindAction("Down", handleMovement, false, Enum.KeyCode.S, Enum.KeyCode.Down)
ContextActionService:BindAction("Left", handleMovement, false, Enum.KeyCode.A, Enum.KeyCode.Left)
ContextActionService:BindAction("Right", handleMovement, false, Enum.KeyCode.D, Enum.KeyCode.Right)
  1. What is the issue? Include screenshots / videos if possible!
    I’m not sure how to begin implementing an integration between my script and the Roblox mobile controls.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have searched on the developer forum and the developer hub.

1 Like

Maybe Roblox’s ControlModule would be helpful.
It can be found at
game.Players.LocalPlayer.PlayerScripts.PlayerModule.ControlModule
while your game is running.

If you require this module then call :GetMoveVector() on it, it will return a Vector3 which will correlate to the direction of the mobile thumbstick (its X and Z components).

Sorry for the late reply, I hope this helps. :slight_smile:

I’ll look into that then, thanks!