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 Pinsukka · Apr 27, 2015 at 09:28 PM · c#androidzoomorthographic

Pinch to zoom acting weird on Android

I watched an Unity tutorial recently on how to write pinch to zoom script in C#. I was able to make it work just as it is supposed to work on my Samsung Galaxy Tab S 10.5, but for some weird reason it doesn't work as it should on my phone (Sony Xperia Z2).

I also have a panning feature so the player can move the camera, this also works great on the tablet, but not on the phone.

The problem is that the zoom/pan movement is not constant, it slows down and speeds up weirdly even when I move my finger at a constant speed. Here is a video clip to demonstrate what the problem is: https://www.youtube.com/watch?v=fn-YPs0iU40

I tried using FixedUpdate() instead of regular Update(), but there is no difference at all. Here is the zoom script:

 public float orthoZoomSpeed = 1.0f;
 public float zoomPercentage; //Controls zoom speed
 public Camera mainCamera;

 void FixedUpdate () {

     zoomPercentage = (mainCamera.orthographicSize / 50.0f);
 
 if(Input.touchCount == 2)
             {
                 Touch touchZero = Input.GetTouch (0);
                 Touch touchOne = Input.GetTouch (1);
     
                 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
     
                 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
     
                 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
     
     
                 mainCamera.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed * zoomPercentage;
                 mainCamera.orthographicSize = Mathf.Max (mainCamera.orthographicSize, 5.0f);
                 mainCamera.orthographicSize = Mathf.Min (mainCamera.orthographicSize, 50.0f);
     
             }
 
 }

There shouldn't be anything wrong with this script, as it works just fine with the tablet. Does anybody have any idea why it doesn't work correctly on the phone? I can't publish anything with this script if I can't get it to work properly, really annoying problem!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Xarbrough · Apr 27, 2015 at 09:39 PM

Your code should use regular Update() for this, or else you might lose input, since the Input class polls at Update() rate not FixedUpdate(). Other than that your script looks fine and I don't know of any particular issue with touches on Android. Maybe you can test on another device and see if its a device issue. And of course you should test your script in a demo scene with nothing else going on. There could always be some interference with other code, UI elements or what not.

Comment
Add comment · Show 5 · 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
avatar image Pinsukka · Apr 28, 2015 at 05:09 AM 0
Share

I see, thanks for the info. I'm quite new to Unity and program$$anonymous$$g so still don't know how all the functions work.

And by the way, the scene in the Youtube clip is an empty scene, there is only the touch script attached to the camera, one sprite (the sun) and nothing else. It's pretty weird how it acts, I tried it with another Xperia Z2 and the same thing happens on both, zoo$$anonymous$$g and panning feels totally unresponsive. I should get my hands on another Android device to test it further I guess, this may very well be some sort of device specific issue.

avatar image Pinsukka · Apr 28, 2015 at 05:31 AM 0
Share

I did some more testing and it seems the same issue happens on the tablet too, it just wasn't so pro$$anonymous$$ent yesterday with FixedUpdate(), but after I changed back to Update() I noticed it. So this clearly is not a device specific issue.

$$anonymous$$aybe I should try doing the zoo$$anonymous$$g and panning different somehow, but I don't really know how to do that. There is not that much documentation about zoo$$anonymous$$g and panning with touchscreen (weirdly, one would think this is quite common thing developers need).

avatar image fafase · Apr 28, 2015 at 05:58 AM 0
Share

Well the place where you got the pinch code is about zoo$$anonymous$$g (or did you get it from elsewhere?):

https://unity3d.com/learn/tutorials/modules/beginner/platform-specific/pinch-zoom

avatar image Pinsukka · Apr 28, 2015 at 06:25 AM 0
Share

Yeah, watched that tutorial yesterday and modified the code a little for my project. It should work, but for some reason it just doesn't... There is other stuff happening in the code too though, maybe that could be the cause?

Here is the full code if someone wants to take a look:

http://pastebin.com/zCPnCCH3

avatar image Pinsukka · Apr 28, 2015 at 07:13 AM 0
Share

I made a completely clean project and watched yet another tutorial on this. Even after writing the script again in slightly different way the same keeps happening: panning and zoo$$anonymous$$g is really unresponsive on both of my devices... This is driving me crazy.

Here is the code I used in the clean project:

http://pastebin.com/Xp6BtvY4

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Mobile Zoom System, That Zooms In On The Right Position 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Receipt JSON Split 0 Answers

Unity 2018.2 LWRP blackscreen on build(Android VR) 2 Answers


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