How to ignore ThumbStick when using when using UserInputService

I am trying to make a 3rd person camera for Mobile Devices and i am using

UserInputService.InputChanged:Connect(function(Input, GameEvent)
 if not GameEvent then
       if(Input.UserInputType == Enum.UserInputType.Touch) then

to get the delta but when i use the ThumbStick it interferes with the Touch Input and messes up the camera

2 Likes

I don’t believe there are any KeyCodes or UserInputTypes that refer to the dynamic/virtual joystick for mobile devices. However if you take a look at the DynamicThumbstick module in the new PlayerModule hierarchy, you can figure out how they handle the movement with it (you can also disable it through this module, it seems)

You can utilize ContextActionService to Bind and Unbind Enum.UserInputType.Touch and return Enum.ContextActionResult.Sink if it does not meet your requirements, which should stop it from going through to interfering with your system.

I haven’t put any of this to the test, just throwing some ideas at you to work off of.

1 Like

i want still want it to work when i am using the thumbstick and paning the camera at the same time

If I understand correctly, you want the 3rd person camera to look in the direction that the character is facing/moving.

In the example video you posted, it appears the rig is being forced to look in the x/z direction that the camera is facing, is that correct?

if so, maybe you should switch your logic around to move the camera based on the rig’s CFrame, and not the other way around.

it would still interfere and i want to be able to pan the camera up and down , another way i thought of doing this is detecting if the the touch input is happening form the right side of the Screen as thats what most mobile games which uses 3rd Person camera do and i could use the dynamic thumbstick since it only detects control inputs form the left. how do i do this?

Two ways you can do this:

  1. (the optimal way) keep the default camera system but restrict movement on the x and y axis by setting it to the desired position every frame.
  2. (the kind of hacky way) detect your touch input on the right side of the screen by getting the position of the touch through InputChanged (as you had originally):

UserInputService.InputChanged:Connect(function(input_object)
    if input_object.UserInputType == Enum.UserInputType.Touch then
        if input_object.Position.X >= screen_size.X/2 then -- it's on the right side of the screen.
             -- do your logic
        end
    end
end)

You’d get screen size by checking the AbsoluteSize on a ScreenGui or workspace.CurrentCamera.ViewportSize

2 Likes

You can see in the OP he had tried this. It is true for the initial tap on the thumbstick.

i am checking that as you can see on the provided code

Another thing you can do is track when the player is using the touch movement inputs. This is pretty much the equivalent of tracking if you’re dragging a GUI element or not (except without the dragging).

Here’s some example code:

local playerModule = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule);
local control = playerModule:GetControls();

-- dragger objects have a property called isDragging and a method onDrag to define the behaviour of the drag

local dragger = require(script:WaitForChild("dragger"));

function dragger:onDrag(guiElement, input, delta)
	-- do nothing...
end
	
-- apply it to track touch control input

local draggedItems = {};

if (control.touchGui) then
	for _, child in next, control.touchControlFrame:GetChildren() do
		draggedItems[#draggedItems+1] = dragger.new(child);
	end
	control.touchControlFrame.ChildAdded:Connect(function(child)
		draggedItems[#draggedItems+1] = dragger.new(child);
	end)
end

local function isInteracting()
	for i = 1, #draggedItems do
		if (draggedItems[i].isDragging) then
			return true;
		end
	end
	return false;
end

game:GetService("RunService").RenderStepped:Connect(function(dt)
	print(isInteracting());
end)

See place file here:
Baseplate.rbxl (14.9 KB)

Hope that helps!

9 Likes

thanks , this helped me out a lot i am not sure if i should mark your post as the solution since I’ve already marked @Fm_Trick s post as solution but ill mark it any way

1 Like