Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Good way to add gestures / swipe support to game (iOS/Android)

Discussion in 'Editor & General Support' started by eses, Jan 12, 2016.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi there,

    I'm looking for tips about touch related assets - I'll be mostly focusing on iOS/Android, looking for support for Joysticks and/or swipes. Also, being able to simulate some non-mouse gestures would be great.

    I've been testing Unity touch features a bit. I've created rudimentary joystick, virtual joystick, d-pad like buttons and multi-touch with touch ID support but after testing these (half finished tests) I'm thinking about some 3rd party solution, as Unity actually doesn't have built in support for anything but touches if I'm correct.

    So are there any good assets for this?

    I already tested Prime31 free TouchKit, but at glance it seems to be bit outdated. It's not using new Unity UI elements in anyway (at least it seems like that) so it require some work get it working.

    Seems like there are 2-3 high profile assets in assets store that handle both touch joysticks and basic gestures - Like Easy Touch 4, which seems like a usable solution.

    Then there are is a bunch of low budget / less featured alternatives.

    So anyone have experience with any of these? I'd be interested to hear your opinions.

    Thanks!
     
    MOSTY likes this.
  2. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I just wrote my own. Unity provides enough helpers with both CrossPlatformInput and Input.<anything touch related> that calculating drags and gestures isn't too hard. I just implemented simple pinch to zoom, drag, select etc. I don't have full on gestures like, draw an H and the game reads "H". That requires some pretty good math foo.

    For quick swipe gestures you just need to check the touchphase of the touch, looking for Moved, and then check the delta of the move. If you're looking for high speed swipes then you want to look at the magnitude of the delta. To get the direction I simply keep a "lastTouchPosition" and subtract the current touch from the lastTouch to get my directional vector.

    Aside from all that, you shouldn't have issues with "out of date" touch libraries if they're compatible with your version of unity. There hasn't been any major advances in touch control with devices in a while so you won't be missing out on any features for using a 2 year old asset.

    my 2 cents.
     
  3. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    523
    TouchKit is small, handy, and free if you're up for modifying it (we've used various custom versions).
    TouchScript is big, great, and free (the latest version integrates with Unity UI, used on a few projects big and small).
    InControl is a sweet input/game controller paid asset that supports some touch input too (integrates with Unity UI, also used on a few projects big and small).

    Some libraries are also starting to support features like pressure/force touch too, if you need it. (We've not used any yet. Unity exposes this input in the latest versions too.)

    You can write your own basic input/gesture support easily enough but things will quickly get quite fiddly once you start needing more complex input and various gestures to work with each other nicely, and then further integrate with Unity UI. You will see in some of the libraries above that there can be quite a few edge cases and a bit of glue code to make everything work nicely. As always, just weigh up the time you want to spend on writing your own vs. using a supported free or paid library. We use libraries so we can concentrate on the other fun stuff - handling input is often not very fun at all :)
     
    RGV likes this.
  4. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Everything said above is true. There's one gotcha though. Whenever you implement someone else's library you are more or less "held back" by it. If it ever breaks or lacks a feature, it's likely not going to be easier to fix it yourself unless you have the source and it's very well documented. For our projects we almost always attempt to write it ourselves. If we find that we can't get the results we want in a reasonable amount of time we start exploring assets. But projects that have tons of different assets for tons of different things are just asking to run into issues.

    Good luck!
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    jtsmith1287: thanks for the reply!

    Yeah, good for you! I figured what you mentioned, would be the solution - I think I can handle those vectors and magnitudes, and I already have registering of touch handled, but the code is definitely bad and most likely will cause big bug hunt eventually :).
    But the fact that I don't have out of a hat solution for testing of one or two finger drag in editor is a problem. Some pre-built solutions have, let alone the fact that compiling to iOS takes some time. I'll have to think if testing in editor could be sorted out without too much headache. Is it somehow possible to add something between Input.Touch stuff, that way I could add support for fake touches, instead writing editor/iOS code side-by-side.

    "touch / out of date" OK, that's good to know, and I suspected that touch systems haven't changed that much as devices haven't, only the fact that many of the older assets don't seem to be familiar with new UI and use hard coded rectangles and such, (like TouchKit), so I'll only see if this causes trouble by taking time and testing these assets.
     
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    greg harding:

    Thank you for good info!

    "TouchKit, TouchScript, InControl" - TouchKit - I actually did another asset store key word search round yesterday and went through my previous notes, and actually did read about all of these assets.
    I tried TouchKit it looks nice, seems like latest Github zip gave errors, there was some lite version which had some errors, moved it out and it started working. Anyway it looked promising, but most likely needs something for defining rectangles and such, but d-pad like buttons seemed to be working nicely.
    TouchScript - I got the first impression it might be a bit complex.
    InControl - Thought it was more for input mapping, will read more about it. It looks quite similart to Easy Touch 4, but have to compare features.

    I also came across some free assets that look nice, I've only tried Lean Touch, but I'm yet to read more about them and do some testing:
    Lean Touch
    Fingers - Advanced Gestures
    CN Controls
    Simple Joystick Unity 4.6+
     
  7. MOSTY

    MOSTY

    Joined:
    Sep 6, 2013
    Posts:
    266
    eses likes this.