Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by arstoykov · Jul 29, 2013 at 11:08 AM · cameradragswipefinger

Drag camera with two finger swipe

Hello!

I'm trying to make the camera to be dragged by placing two fingers on the screen and swiping them up/down - left/right, but with no success by now. I've made it draggable with one finger, but am still struggling to make it move with two-finger swipe.

Here's my approach:

 public float dragSpeed = 10;
 private Vector2 dragOrigin;
 private Vector2 startPoint;
 void Update()
 {
     
     if (Input.touchCount > 1){
         dragOrigin = GetInputRange();//Input.GetTouch(0).position;
         return;
     }else{
         return;    
     }

 Vector3 pos = Camera.main.ScreenToViewportPoint(Input.GetTouch(0).position - dragOrigin);

     Vector3 move = new Vector3(-pos.x, -pos.y, 0);
     transform.Translate(move, Space.World);
 }


 static bool IsBegun(Touch touch1, Touch touch2)
 {
     return (touch1.phase == TouchPhase.Began && touch2.phase == TouchPhase.Began) ||
             (touch1.phase == TouchPhase.Stationary && touch2.phase == TouchPhase.Began) ||
             (touch1.phase == TouchPhase.Moved && touch2.phase == TouchPhase.Began);
 }  
 
     Vector2 GetMidpoint(Touch touch1, Touch touch2)
 {
    return Vector2.Lerp (touch1.position, touch2.position, 0.5f);
 }
     
     Vector2 GetInputRange()
     {
         if(Input.touchCount < 2)
            return Vector2.zero;
      
         Touch touch1 = Input.GetTouch(0);
         Touch touch2 = Input.GetTouch(1);
      
         var midpoint = GetMidpoint(touch1, touch2);
      
         if(IsBegun(touch1, touch2))
              startPoint = midpoint;
          
         return startPoint;
  }

I'd be grateful if someone could land a hand. Thank you :)

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lovrenc · Jul 29, 2013 at 11:09 AM 0
Share

platform?

avatar image arstoykov · Jul 29, 2013 at 11:30 AM 0
Share

Android and iOS

avatar image Owen-Reynolds · Jul 29, 2013 at 03:29 PM 0
Share

Would help if you said what was wrong with it. But, Update can't reach line 14 (you should be seeing warnings about that.)

Then, just for ease of reading, IsBegun seems redundant -- could just check whether touch2 has begun.

avatar image AlucardJay · Aug 04, 2013 at 05:30 AM 0
Share

There is a great resource on the Unity Wiki.

  • Tap to $$anonymous$$ove Drag to Look iPhone : http://wiki.unity3d.com/index.php/Tap_to_$$anonymous$$ove_Drag_to_Look_iPhone

  • and : http://wiki.unity3d.com/index.php/Finger$$anonymous$$anager

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScottYann · Aug 04, 2013 at 12:01 AM

I don't want to sound like an EasyTouch Shill (how do you know I'm not?) but it makes touch control so much easier that trying to do it with unity alone. There are also other touch managers in the asset store that might work just as well..

It was worth what ever I paid for it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error. Unity can't seem to find my camera when set as a game object. 1 Answer

Camera momentum after lifting finger 0 Answers

Another camera drag script, can anyone figure out these errors? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Camera to follow the player in the form of radius 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges