How to detect if a input movement from a mobile user and a xbox user

This is a difficult thing that I struggle with the most when it comes to scripting custom gameplay controls for xbox and mobile users, and that is detecting when they’re moving W/A/S/D wise.

I always look through the wiki and when ever I try using the events provided, it just doesn’t work asI wanted it to. I just want to know when a mobile/xbox player is trying to move W/A/S/D wise so I can make my own custom literally camera move from left/right forward/backward but I’m always doing it wrong and I can never figure out why or how. Am I using the wrong events?

Mobile Controls Try

local InputService = game:GetService("UserInputService")
local CurrentDirection = "None"
	InputService.TouchSwipe:connect(function(swipeDirection)
		if swipeDirection == Enum.SwipeDirection.Up then
			CurrentDirection = "Up"
			GoingUp = true
		elseif swipeDirection == Enum.SwipeDirection.Down then
			CurrentDirection = "Down"
			GoingDown = true
		elseif swipeDirection == Enum.SwipeDirection.Left then
			CurrentDirection = "Left"
			GoingLeft = true
		elseif swipeDirection == Enum.SwipeDirection.Right then
			CurrentDirection = "Right"
			GoingRight = true
		else
			GoingUp = false
			GoingDown = false
			GoingRight = false
			GoingLeft = false
            CurrentDirection = "None"
		end
	end)

Xbox Controls Try

local InputService = game:GetService("UserInputService")
InputService.InputBegan:connect(function(Input)
		if Input.UserInputType == Enum.UserInputType.Gamepad1 then
			if Input.Position.Y > 0.1 then
				GoingUp = true
			elseif Input.Position.Y < 0.1 then
				GoingDown = true
			elseif Input.Position.X > 0.1 then
				GoingRight = true
			elseif Input.Position.X < 0.1 then
				GoingLeft = true
			end
		end
	end)
	InputService.InputEnded:connect(function(Input)
		if Input.Position.Y > 0.1 then
			GoingUp = false
		elseif Input.Position.Y < 0.1 then
			GoingDown = false
		elseif Input.Position.X > 0.1 then
			GoingRight = false
		elseif Input.Position.X < 0.1 then
			GoingLeft = false
		end
	end)

This is the loop script under the controls

while Player and Camera do
	local CameraMovementSpeed = 2
	CurrentHeight = (Camera.CFrame.Position.Y-MainPlate.CFrame.p.Y)
	if GoingUp == true then
		Camera.CFrame = Camera.CFrame*CFrame.new(0, CameraMovementSpeed, 0)
	end
	if GoingDown == true then
		Camera.CFrame = Camera.CFrame*CFrame.new(0, -CameraMovementSpeed, 0)
	end
	if GoingRight == true then
		Camera.CFrame = Camera.CFrame*CFrame.new(CameraMovementSpeed, 0, 0)
	end
	if GoingLeft == true then
		Camera.CFrame = Camera.CFrame*CFrame.new(-CameraMovementSpeed, 0, 0)
	end
	game:GetService("RunService").RenderStepped:wait()
end

Edit: I have looked through several posts similar to this but none of them provide a solution for me.

3 Likes

I have just started on this journey of discovery too. Have you progressed any further? I don’t think TouchSwipe is related to the mobile touch / virtual joystick. I was hoping there was an equivalent to the isKeyDown method only for the virtual joystick.

I did find this comment from @EmeraldSlash on another post surely you can access when the control is being used?