-
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)
-
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. -
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.