#input manager

1 messages · Page 1 of 1 (latest)

dusk token
#

hello, im trying to add mobile support to my game, and its not working properly
basically what im trying to do is make it so that if you hold your finger for 0.5 on one spot we start visualizing
it should ignore all other inputs that arent that; so for instance we can move, hold a finger and then start visualizing, or hold a finger, start visualizing and then move, i hope you get the idea

local inputChanged, inputEnded
local activeTouch = nil
local holding = true

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end

    if input.UserInputType == Enum.UserInputType.Touch and not activeTouch then
        local startPos = input.Position
        holding = true
        activeTouch = input

        task.delay(HOLD_TIME, function()    
            if holding then
                local touchPos = startPos
                Visualizer:Begin()
            end
        end)

        inputChanged = UserInputService.InputChanged:Connect(function(moveInput)
            if moveInput == activeTouch then
                local moved = (moveInput.Position - startPos).Magnitude
                if moved > MOVE_THRESHOLD then
                    holding = false
                end
            end
        end)

        inputEnded = UserInputService.InputEnded:Connect(function(endInput)
            if endInput == activeTouch then
                fire()
                    
                activeTouch = nil
                holding = true
                if inputChanged then inputChanged:Disconnect() end
                if inputEnded then inputEnded:Disconnect() end
            end
        end)
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
        Visualizer:Begin()
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        fire()
    end
end)```
tropic siren
#

You shouldn’t use UserInputService

#

Use ContextActionService or InputActionSystem

dusk token
#

i will, thx, but how should i approach the problem i am trying to solve though

#

am i on the right path

#

cuz it does work to some extent, meaning that when im holding the finger, starting the visualization and moving it works

#

but it doesnt work vice versa

tropic siren
#

To simplify this a bit, you want it that so when a mobile users holds down a button for more than 0.5s, you do something?

dusk token
#

right

#

but i want to ignore every other input, that comes before or after that

tropic siren
#

local CAS = game:GetService(“ContextActionService”)

local holding = false

CAS:BindAction(“Visualizer”, function(_, state)
if state == Enum.UserInputState.Begin then
holding = true
task.delay(0.5, function()
if not holding then return end

Visualizer:Begin()
end)
end
end, false, Enum.UserInputType.Touch)

queen zincBOT
#

studio** You are now Level 3! **studio

dusk token
#

ive never used cas before, and if this works then im just gonna snap lmao

queen zincBOT
#

studio** You are now Level 1! **studio

dusk token
tall elbow
queen zincBOT
#

studio** You are now Level 13! **studio

dusk token
tall elbow
#

Userinputservice

#

.Touchstarted and .TouchEnded events

tall elbow
dusk token
tall elbow
#

You could use CAS and create a special button for it

tall elbow
dusk token
zenith mason
#

wat is not working

dusk token
#

so basically if you start moving, and then try holding the finger, it doesnt work

#

it's really specific, everything other than that works fine i guess

dusk token
# zenith mason wat is not working

also you shouldnt be able to move the finger around the screen, stop it and get the visualization, the initial input should be held and if it isnt it should just be ignored i hope u get what im trying to say

zenith mason
#

need to be more specific on what you mean by "doesnt work"

#

not working could mean a lot of different things

dusk token
queen zincBOT
#

studio** You are now Level 2! **studio

dusk token
zenith mason
dusk token
#

for some reason i couldnt make it work normally, i tried doing the moveInput == activeTouch outside of the inputbegan and it didnt work

zenith mason
#

this in inputbegan is very strange too lua task.delay(HOLD_TIME, function() if holding then local touchPos = startPos Visualizer:Begin() end end)

dusk token
#

ive tweaked the code a lot of times, but yeah touchPos is useless in there

dusk token
zenith mason
#

do it again

dusk token
# zenith mason ja, just refactor

okay so it works now, but im still facing the same problems like i did before

local activeTouch = nil
local holding = false
local startPos

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end

    if input.UserInputType == Enum.UserInputType.Touch and not activeTouch then
        activeTouch = input
        holding = true
        startPos = input.Position

        task.delay(HOLD_TIME, function()    
            if holding then
                local touchPos = startPos
                LassoVisualizer:Begin(touchPos)
            end
        end)
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
        local mouse = player:GetMouse()
        LassoVisualizer:Begin(mouse)
    end
end)

UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Touch and input == activeTouch then
        local moved = (input.Position - startPos).Magnitude
        if moved > MOVE_THRESHOLD then
            holding = false
        end
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        fire()
    elseif input.UserInputType == Enum.UserInputType.Touch and input == activeTouch then
        fire()

        activeTouch = nil
        holding = true
    end
end)

now im also passing the touchPos (and mouse) into the function, which fixed a problem where it was constantly moving from 1 finger to another

#

im not sure if this works though

input == activeTouch

#

like can i even do that?

zenith mason
#

activeTouch = true ?

dusk token
#

i want to be able to do all of this, and at the same time move the character, the screen or whatever

zenith mason
#

aren't you already checking if the input is touch?

#

gameprocessedevent already catches those

dusk token
#

im a bit lost im sorry, should i just delete the activeTouch then altogether

zenith mason