I’m at day 2 of trying to make a over the shoulder camera compatibility for mobile, and using Humanoid.MoveDirection, the script can detect if the player is using the thumbstick.
The problem is that I still want the player to be able to move their camera using another finger that’s not operating the thumbstick.
So, I tried adding booleans to detect if the touch is either “firstTouch” or an “extraTouch”.
local touchCamera = UserInputService.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state, gpe) if state == Enum.UserInputState.Begin then if gpe then return end if firstTouch == true then extraTouch = true end if humanoid.MoveDirection ~= zeroMovement and firstTouch == false then firstTouch = true print("firstTouched") end end if state == Enum.UserInputState.Change then if humanoid.MoveDirection ~= zeroMovement and not extraTouch then return end -- Camera Code Omitted for the sake of space -- end if state == Enum.UserInputState.End then if extraTouch == true then extraTouch = false print("extraTouchFalse") end if firstTouch == true and humanoid.MoveDirection == zeroMovement then firstTouch = false print("firstTouchedFalse") end end end)
The logic is supposed to go:
- Player touches screen.
- If the player doesn’t have a moveDirection then it means they aren’t using the thumbstick so the camera code will run.
- If the player does have a moveDirection then it means they are using the thumbstick, the camera script will not run and it will register the touch as a “firstTouch”.
- If the player touches and pans the screen again while “firstTouch” is true then this will turn the “extraTouch” boolean to true, thus the camera code will run.
- If the person releases a finger from the screen and the moveDirection is Vector3.new(0,0,0) then that means they aren’t using the thumbstick and they released the finger that set “firstTouch” to true, so “firstTouch” is set to false.
- If a finger is released and the humanoid.MoveDirection isn’t (0,0,0) then that means the finger they released was their “extraTouch”, so extraTouch is turned off.
The problem with this is that the .TouchPan is stuck on the “firstTouch” and seemingly doesn’t detect a second touch until you release the “firstTouch”, so “extraTouch” is never set to true, thus the camera code never runs.
I’d show a gif of this, but Roblox Studio doesn’t trigger .TouchPan in its emulator (and I only have 1 mouse).