- Home /
 
TouchPhase.Ended not firing?
I'm trying to push an object in the direction of the user's swipe in my Android game. This is the code I'm using. It doesn't seem as though TouchPhase.Ended is ever called, though. Does anyone know what's up?
 function Update () {
     for (var touch : Touch in Input.touches) {
                             
         if (touch.phase == TouchPhase.Began) {
             startPos = touch.position;
         if (touch.phase == TouchPhase.Ended) {
             endPos = touch.position;
             rigidbody.AddForce(Vector3(endPos.x-startPos.x,endPos.y-startPos.y,0) * 500 );
             myGUI.text = (endPos.x-startPos.x).ToString() + "  " + (endPos.y-startPos.y).ToString();
             }
         }
     }
 }
 
              Answer by whydoidoit · Jan 26, 2013 at 09:22 AM
That problem occurs on iOS when the framerate is such that not all of the events are captured. I'm not sure on Droid but I'd bet it's something similar. I ended up writing my own handler class that notices that a finger is no longer down and returns "Ended" for that frame itself.
Well, you could check the fingerID which you should use anyways. Your code above will do strange things when you put two fingers down.
Also you usually should check for both: "Ended" or "Canceled". Only one will happen. Personally iÄve never seen that an Ended / Canceled event was missing even at very low framerates around 4fps.
ps: Btw, If you use AddForce for a one time impulse you should use a different Force$$anonymous$$ode either Impulse or VelocityChange. Force and Acceleration should only be used for continuous forces in FixedUpdate
Ah. I see the problem—I bracketed the functions wrong. In the code above, it only checks if the phase is Ended IF the phase is Began. It can never be both so it never activates that code.
Answer by letroll · Sep 19, 2015 at 04:05 AM
I'm having the same issue with swipe in my Android game, but with FixedUpdate(). With Update() it's seem ok
Your answer