I came across a very strange bug.
I have an iPhone 11 Pro and I have been building the project onto it from the beginning and it worked perfectly. Once I released my game to the public, I got some reports that the functionallity that alternates between “dragging” and “selecting” was being an issue (Probably because the code thinks the person is dragging instead of selecting).
So, I tested it out on three different iPhoneX’s (Xs and X) and one iPhone 7 and it really has the issue the users were claiming.
What is weird is that it works perfectly on Android phone’s and in mine iPhone 11 Pro.
I am posting this because I have no clue of what this might be. I already have the “Drag Threshold Fix Script” added to my EventSystem.
I have and old post in which I explain in detail exactly what I did regarding this “dragging and selecting” code.
Just added some code that gets the position of the touch when it begins and when it stops dragging to see if I could add an error margin to correct this but the result was curious.
It goes to the “drag state” even though both positions are the same! I have no idea why the touch.phase is becoming TouchPhase.Moved given that starting and ending positions are exactly the same (even the decimals).
This is getting very awkward… I have no idea how to proceed.
Are you comparing floating point numbers for equality? You should compare them for approximately equal, or as we spoke in the other channel, a guard amount to avoid finger wiggle.
With floating point numbers, two numbers that display identically can still be different internally and fail equality check. That’s why we never compare floating points for equality, only less than or equal, or compare difference for below a value.
For the “guard” distance, I usually consider anything less than 5% of the small axis of the screen (in pixels) to be not moved. Some cheap android devices have noisy touch input, so the finger appears to jitter around a bit.
float minDragDistance = Mathf.Min( Screen.width, Screen.height) * 0.05f;
if (distanceDragged >= minDragDistance)
{
// consider it a drag
}
I came to the same conclusion and solved it in a similar way just moments ago. I just think this is kind of weird still… I can’t see a case in which a developer would use a built in function called Touchphase.MOVED that would not work properly due to jitters.