How can I achive faster response time from Input?

I’d like to make a game, in which the player has to quickly connect buttons with a swipe in the right order. It’s the core interaction in the game, so it’s important that this should work perfectly.

My problem is, that if there are 3 buttons in a row, and I’d like to select those with a real quick swipe (or for testing purposes with a mouse), I can’t select all of them. Sometimes the middle one, or even two of them is missed, even though I’m absolutely sure, that the swipe or the mouse cursor went straight over them.

After a bit of debugging I found that if I print out the touch or mouse position, it skips a whole lot of pixels. With real fast mouse movement the game skipped more than a hundred pixels between two frames! (That’s enough to jump over the buttons.) I use Input.mousePosition in the Update function for testing on my PC.

This is a 2D game with a few moving sprites at this stage, so there shouldn’t be anything that slowes down the game. The game doesn’t seem to lag, only the input is too slow for the quick motions.

Is there a workaround for this? Maybe I missed a parameter in the preferences? I managed to do this in cocos2dx on a really old android mobile without a problem, no skipping buttons. This shouldn’t be a problem for Unity too. I’d really like to use Unity, but this issue is a game breaker.

I know this is an old one, but I couldn’t find the solution so far.

Sounds like you are moving extremely fast. Any Input within Unity should be updated once per frame as per this thread. Not really sure how you can fix this to be honest other than getting a third party asset that is able to get raw input data separately from Unity or something.

Alternatively, here is a huge thread created by Unity talking about the Input system and how it can be improved. There are a lot of good user posts in there but I don’t have the time to read through it all to see if anything answers your question more specifically.

Have you tested in an empty scene and with minimal object active? What is your framerate? Have you used the profiler to root out any huge performance hits or something else causing problems?

In most cases, I would say input is polled fast enough to get you fine results. Maybe if you can upload your test scene, I or somebody else can take a look at it.

I’m not good at math, but let’s try: e.g. your screen is 1920 px wide, you have 60 frames per second, if your button is 100 px wide, you need to move your mouse more than 6000 px per second to actually have a chance of missing the button, correct? Doesn’t sound likely. What if your button is 20 px wide and you’re running at 15 frames? Then you would need a speed of 300 px/s to skip the button. This sounds possible.

If you made sure, that you’re really skipping buttons because your pointer moves faster than the update loop can track pixel in that time, you can of course try to fix other performance problems to speed up the update loop and so on, but it’s also possible to interpolate/extrapolate your pointer movement. You can measure the starting point and the end point from one frame to the next, which would normally be used to get the “mouseDelta” movement. You can use this vector to actually check, if it intersects the button, this way you don’t miss it, even if your mouse moves incredibly fast.

Thanks, both of you!
For clarity I created a test scene, and I attached my little scipt, also in unitypackage format.
To me the fps looks fine (70-120 if this FPSDisplay I found online is correct), but I still manage to skip a button. I first thought that maybe I’m not accurate with the movement, but how can I skip the middle button?
Take a try if you want, maybe this is just a noob mistake :slight_smile:
This test is far from good I know, just a basic thing for you to try.

Happy Holidays!