- Home /
Need Clarification on some Touch Struct Variables
After going through all available documentation and quite extensive searches on the internet I'm still not quite clear on how the following are implemented in Unity:
Touch.fingerId: Apparently, an integer is automatically assigned to this variable when a touch occurs. Through Internet searches I found that the first number assigned is 0, and that subsequent touches get assigned numbers in increments of 1, so if 5 fingers touch the screen one-after-another, the fingerId's assigned will be 0,1,2,3,4. My questions are: a. What if the first finger (fingerId=0), is raised and then immediately touches again, and then raised and retouched one more time. Would it lose the fingerId=0 assignment, and get a 5 and then 6 assignment on the subsequent 2 touches? b. What if fingers corresponding to -say- fingerId=2 and 4 were raised, and after some time they retouched the screen, while the other 3 fingers were still touching and with fingerId's=0,1,3. Would the 2 'new' fingers get assigned fingerId's=5, 6, or would they fill the gaps with fingerId's=2,4? In the former case, is there a limit to the sequence of touches, and hence the range of the fingerId's, or is this just limited by the int type? c. Do the fingerId's persist for a 'touch sequence', i.e. until there are no more screen touches, and then the auto-numbering starts from 0 again?
Touch.tapCount: This records number of taps for a specific Touch, and hence for a specific fingerId. However, if a finger is raised TouchPhase.Ended is fired, signifying the end of a Touch, and thus the end of the specific fingerId. So, how can this happen? How can tapCount, report a count of -say- 3 taps for a specific fingerId, if this fingerId gets cancelled once the finger gets raised (after the initial tap) and TouchPhase.Ended is fired?
I thank you in advance for your attention and help.
hey pako for the record. if you follow through the incredibly long example i already linked to, it will fully explain it
put down say five fingers. they will be 0 to 4 in the order you put them down
lift up say the first two, and now only numbers 2 and 3 remain
if you keep your number 3 finger down, for all time the fingerId WILL refer to that one. really it's an incredible system. INCREDIBL$$anonymous$$ if I went back to program$$anonymous$$g native mac code say I'd be unwell.
as i explained at ridiculous length in the linked post, the critical element is that Unity DOES fill from the lowest number up, which is incredibly handy (on most systems until now you had to like match back the id number)
hope it helps
TouchPhase.Ended absolutely fires without fail. you can trust your life on it.
http://answers.unity3d.com/questions/326253/strange-touch-behavior.html#answer-326285
it is all explained at vast length over and over and over right there
And (as it says there :) ) never use the silly GetTouch helper function
it's crap.
it's amazingly easy to use fingerId with Input.touches, even for the most sophisticated handling, as shown
i love input engineering, and unity's system is really great.
(yes, you ignore the silly GetTouch function - but that's just like ignoring networkinstantiate in their awesome networking, no big deal.)
consider
if ( TouchPhase.Ended || TouchPhase.Canceled )
Fattie (or $$anonymous$$ike) : regarding a comment I made on your above link; I mentioned that more than 5 touches would cancel all touches, then Gregzo taught me for iPad you can have 11 touches. So checking the the API for TouchPhase.Canceled I read (for example) the user puts the device to her face or more than five touches happened simultaneously.
API link : http://docs.unity3d.com/Documentation/ScriptReference/TouchPhase.Canceled.html
Without an iPad device it doesn't really affect me but I guess it just means cancelled = number of touches exceeded for the device max input touch length. I probably should ask a question, huh?! (no device = not yet affected) =]
alu one half-answer: I'm pretty sure (A) you can SAFELY IGNORE THE CANCELLED OPTION as the others encapsulate it and I'm quite sure (B) it seems very tittchy, it depends greatly on the device etc / often oes not really exist and (C) unfortunately I never fully investigated it so I can't give you a decisive answer, but it;s an admirable question
regarding the "max number" issue. you are right it totally varies on all sorts of devices. (the fact that they mention "five" on that page is random)
sorry for weak input on this :O
Answer by whydoidoit · Oct 22, 2012 at 09:05 PM
iOS/Droid is allocating the FingerIds - you should consider them to be opaque because it is doing clever stuff to work out if this is the same finger - this is also the answer to your second question. tapCount can only be greater than 1 if the OS has figured out that this is the same finger.
You use a fingerID to track the movement of a single finger, you should not expect specific values even if they appear to be consistent on some platform, it's certainly possible that the fingerID for real finger would change between calls, despite the best efforts of the OS to make it persistent - so the only thing you might get is the tapCount being > 1 because the OS is reporting that.
Thank you for your response. If as you say, "tapCount can only be greater than 1 if the OS has figured out that this is the same finger", this means (I think) that TouchPhase.Ended does NOT always fire when a finger is raised (i.e. during a detected tap sequence). I'll do some testing to check things out.
No I believe that ended is always fired when a finger is raised and tapcount is greater than one when the os figures out that it is the same finger tapping (probably repeated taps on the same part of the screen in a limited period of time).
I was actually working on understanding tap a LOT the last few days. What it appears to be doing (at least on android devices) is enumerating the number repeated taps at a given screen location. It appears to continue incrementing the tap count as long as the tap is the same fingerID and hitting the same screen coords (I believe there is some fuzz as to if it is exactly the same touch location or not). The var appears to clear when a touch (with ANY fingerID) lands on a different screen coord.
Fattie who has the answer earlier in the thread dumped some debug code on me in my question about the bounding of that variable. I was able to extrapolate it and wrote some test code of my own and that's the conclusion that I ended up co$$anonymous$$g up with.
I don't really feel like that's the "best" way to get the taps. I'll most likely need to write my own "tapCount" method.
I'm not saying I found a bug at all. I am saying the expressed definition of what tapCount does in the script reference is junk.
I am talking about this function
http://docs.unity3d.com/Documentation/ScriptReference/Touch-tapCount.html
I was totally unclear as to how that number was being bounded. When it was reset etc. I was just saying that "tapCount" is not being cleared out when a tocuhPhase ended or anything like that. tapCount seems to be counting the consecutive number of tap at a given screen coordinate by an expressed finger. What causes tapCount to reset to 1 is using that fingerID finger to tap a different screen coordinate.
I'm not in any way questioning the linked answer. Just kinda providing a short form answer based on what I personally have been doing. I was initially under the impression that tapCount was being bounded by some kind of deltaTimer since the last touch ended or something.
Ahh ! I'm glad you mentioned this issue, sorry I misunderstood you previously. i will delete my pointless comment
"tapCount" is a total mystery. obviously it's utterly undocumented so nobody has a clue what it does.
it is fantastic that someone - you - have delved in to this field!
Currently you are the only living person in the universe who has the slighrest clue what it does !
You are like this guy ...
http://en.wikipedia.org/wiki/$$anonymous$$_Livingstone
exploring totally uncharted areas.
So what the heck does it do? what is a "tap" ?? does it happen over time or?