How to detect a swipe over a game object and record the direction.
Hi, I am trying to make a fast paced app where I need objects to be swiped either left or right quickly. I have managed to implement this but very roughly, and sometimes objects register touches incorrectly or not at all.
I need some help writing code that detects when a game object is swiped over and registers the direction either left or right. I need it to work efficiently, so that no touches are ever missed or preferably with multitouch. Please help.
Answer by StupidlySimple · Aug 06, 2016 at 02:09 PM
Simple Logic:
On Finger Down: Record Position Initially On Finger Move/Up: Record Position Final
Compare Final.x and Initially.x Compare Final.y and Initially.y
If ( Final.x > Initially.x ) - It's right else it's left If ( Final.y > Initially.y ) - It's up else it's down
More Information: https://docs.unity3d.com/Manual/MobileInput.html
If you use mouse, change "finger" to "mouse" ^^b and you're good to go.
Thanks for this, but I have tried this logic already using recasting, but it doesnt support multiple touches at once / dragging over an object, and is sometimes unreliable. Also it is lengthy, and I need code to detect directional movement over an object reliably.