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 DBurge · Jul 17, 2013 at 12:10 AM · androiderrortouch

Problem with Input.touchCount == 1

Howdy Everyone! I have an orthographic camera facing z negative at positive z = 20. I want the player to pan the camera with one finger and zoom the camera when they pinch. So far I have the pinch function working but I can't figure out why my pan function broken. Can anyone tell me what I'm doing wrong?

 #pragma strict
 
 import UnityEngine;
 import System.Collections;
  
 
 var speed : int = 4;
 var selectedCamera : Camera;
 var MINSCALE : float = 2.0F;
 var MAXSCALE : float = 5.0F;
 var varianceInDistances : float = 5.0F;
 
 private var touchDelta : float = 0.0F;
 private var prevDist : Vector2;
 private var curDist : Vector2;
 private var startAngleBetweenTouches : float = 0.0F;
 private var midPoint : Vector2; 
 
 
 function Update ()
 {
 
     if (Input.touchCount == 1)  // 
     {
         var touchDeltaPosition : Vector2 = Input.GetTouch(0).deltaPosition;
         selectedCamera.transform.parent.transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);
     }
 
     
    
        // droid zoom controls
     if (Input.touchCount == 2) // && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved)
     {
        
        
         midPoint =  Vector2(((Input.GetTouch(0).position.x + Input.GetTouch(1).position.x)/2), ((Input.GetTouch(0).position.y - Input.GetTouch(1).position.y)/2)); //store midpoint from first touches
         curDist = Input.GetTouch(0).position - Input.GetTouch(1).position; //current distance between finger touches
         prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition)); //difference in previous locations using delta positions
         touchDelta = curDist.magnitude - prevDist.magnitude;
 
        
         if ((touchDelta < 0)) //
         {
             selectedCamera.orthographicSize = Mathf.Clamp(selectedCamera.orthographicSize  + (1 * speed),2,90);
         }
        
 
         if ((touchDelta > 0))
 
         {
             selectedCamera.orthographicSize = Mathf.Clamp(selectedCamera.orthographicSize  - (1 * speed),2,90);
         }
                  
     } 
              
 }
 
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 Owen-Reynolds · Jul 17, 2013 at 03:19 AM 0
Share

What's wrong with it? Does nothing? $$anonymous$$oves too slow/fast? A fun trick is to make a GUIText and print touchCount and deltaPos in it.

avatar image robertbu · Jul 17, 2013 at 05:43 AM 0
Share

You likely copied the code from the reference. Since you are facing negative 'Z' you'll likely have to change the sign of one of the values you are passing to Translate().

In addition touchDeltaPosition is in screen coordinates, so getting an object to match up with your finger movement will be next to impossible, and if you got something close it would only work on a single resolution. That is this will work to move the object in the same general direction as the finger moves, but the movement won't track the finger.

avatar image DBurge · Jul 21, 2013 at 06:31 PM 0
Share

Sorry for the late response. The camera does not move when the user touches with one finger. It should move along the x/y axis and not move the z at all base on how far the user's finger moves (touch delta).

The translate function looks like this Translate(-touchDeltaPosition.x speed, -touchDeltaPosition.y speed, 0);

avatar image robertbu · Jul 21, 2013 at 07:11 PM 0
Share

Since it is a public variable, verify the value of 'speed' in the inspector. If it is set appropriately, put a debug statement between lines 25 and 26:

 Debug.Log(touchDeltaPosition);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DBurge · Jul 22, 2013 at 01:40 PM

I figured it out, the problem was with the translate function

selectedCamera.transform.parent.transform.Translate

should be

selectedCamera.transform.Translate

Thanks for the help!

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

16 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

Related Questions

Scripts don't work when i try app 2 Answers

Jumping with touch input. 0 Answers

Make sphere shoot to Touch.position error 1 Answer

Android build problem! 1 Answer

Unity Touch=2 commends? 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