Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to code a two finger pan?

Discussion in 'iOS and tvOS' started by Entity3Limited, Aug 3, 2013.

  1. Entity3Limited

    Entity3Limited

    Joined:
    Jan 10, 2012
    Posts:
    21
    Hi,

    I rarely need to ask because I can usually find all the answers I need, but this time I can not ;-( Hope someone can help.

    What I would like to do is be able to pan around a 2D scene when the user touches with two fingers and moves them across the screen.

    Much like the navigation used in 'Ice Breaker'.

    If any one can provide help or an example I would be very grateful.
     
  2. Entity3Limited

    Entity3Limited

    Joined:
    Jan 10, 2012
    Posts:
    21
    Here is the code I have so far. But its just not great.

     
  3. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    Easiest way I've found to do this is:

    1) When two fingers are down store the average position of both fingers in a Vector2 (the centre point between them). Also store the xy of your 2d scene camera.

    2) In each update loop get the new average position between the fingers

    3) Subtract this position from the 1st position you recorded (in step1) to get the delta. Add this onto the stored xy camera and use that as your current camera position

    Tony
     
  4. ptdnet

    ptdnet

    Joined:
    Apr 20, 2011
    Posts:
    100
    This. Make sure there's two fingers (and impose a distance limit for them if you want), then pretend a point in between them is a "virtual finger." Now track that finger and see where it's going.