Latency with android touch
Hello. Maybe someone ask for this but i don't find it.
Had a very simple code: Pass my finger on a ball to push it. So just a ball and the floor (not too many object!!!).
In the editor with Input.GetMouseButton it work well. But when i test it on android device, there's a very short latency when my finger pass on the ball, and when the force apply on it. So it works, but doesn't look great !
I tried many sort of detection, thought that is maybe the problem. Test with update, fixedUpdate, reduce timestep etc...
But at the end, i think that the problem of latency is the response of touch in android. Am i right ? And is there any solution ?
Thanks (Sorry i'm not english, so forgive my mistake)
Answer by meat5000 · Apr 03, 2018 at 12:03 PM
You'll see this is a common issue. You should implement Input.touches instead https://docs.unity3d.com/ScriptReference/Input-touches.html
~
Ive read about foreach having some issues (maybe performance related) compared to a for loop. It shouldnt cause this kind of issue. I would suspect you are running touches from FixedUpdate. Try Update instead.
If you use different methods in editor and device, use proper 'platform specific directives'.
Thanks for your answer. But i made a mistake in my question. Sure i am using Input.touch when i run it on android. I try with foreach (Touch touch in Input.touches), think foreach go slower so try : if (Input.touchCount == 1) and if (Input.GetTouch(0).phase == TouchPhase.Began) etc... But the performance still remain the same.
Sorry, but in my question i wrote it, i try with both Update and FixedUpdate. Think i had to calculate the vector and it the ball in advance of when my finger is really on it, to handle this very short latency.
I don't understand "use proper 'platform specific directives'". I wrote the code on a computer wich not have touch. So for rapid test in the editor i use mouse, and touches when i test it in android. With #if UNITY_EDITOR. Is there a way to simulate touches in the computer ?
You need to remember that when the editor is in Android mode it will execute Editor and Android behaviours. This can give debug issues. You may see that it works but in actual fact the Android part has failed and the editor part is the one thats giving the results, leaving you thinking the Android code is fine.
Ins$$anonymous$$d of
#if UNITY_ANDROID
#endif
#if UNITY_EDITOR
#endif
Try something like
#if UNITY_EDITOR && UNITY_ANDROID //For code in Editor
#endif
#if !UNITY_EDITOR && UNITY_ANDROID //For code on Device Only
#endif
and see if there is a difference.
~
If you find you have to resort to precalculation, perhaps the issue lies within that code.
Had to go. I tried #if UNITY_EDITOR && UNITY_ANDROID... later to see if i have the same behaviour on the editor. Thanks for your time.
Your answer
Follow this Question
Related Questions
When The Screen Is Touched Jump 0 Answers
Android Touch Double Jump - Not working 0 Answers
Drag and Drop Touch Collision 1 Answer
Unity Input Touch 0 Answers
Android Controls 1 Answer