Hey fellow developers!
I have got a problem with creating a custom camera movement system. I want to track the position of the player’s finger on a mobile screen, therefore I am using the InputChanged event. On PC, the InputChanged event is fired several hundreds of times per second, and on mobile, it seems that it is capped on a maximum of 60.
Here is the code that I am using:
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
local firstTick = nil
local count = 0
if UserInputService.TouchEnabled then
UserInputService.InputChanged:Connect(function(input, gameProcessedEvent)
if not firstTick then
firstTick = tick()
end
local delta = tick() - firstTick
if delta >= 1 then
print(count, "count")
firstTick = tick()
count = 0
else
count += 1
end
end)
end
end)
I am under the impression that the framerate on desktop is also capped at 60hz. Lets agree on the fact that the framerate isnt 600+, as the output suggests. Does anybody know why this is happening?
The problem is that you’re connecting a callback every time there’s any sort of input from the user which causes the connected callbacks to grow into the numbers you’re seeing. If you really need to connect a callback to an event inside of another callback use :Once() instead of :Connect() or call :Disconnect() on the connection when you’re done with logic execution.
The first time InputChanged will have just one callback, on the second input it will have 2: the one from the first input and the one that was just added. With this pattern the connected callbacks will stack up infinitely.
Thanks for taking time to respond. Even if I disconnect or use once, the 60hz cap still remains being there on mobile.
Could you think of any other possible solutions?
I also noticed that the same occurs when using TouchMoved; it seems the problem is dependent of the device used. Is there any way to still detect every moment the input was changed instead of just 60 times per second?
The thing is that you can’t generate things that are never physically (elaborated by the GPU) rendered so the smoothness depends on the max frame rate.
It’s because of optimizations on Mobile, you, as a user of the platform cannot disable the cap. Its solely so that Roblox doesn’t run like crap and doesn’t crash or run into issues on Mobile, due to the increase constraints.