• 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 /
This question was closed Apr 18, 2013 at 03:56 AM by SirGive for the following reason:

The question is answered, right answer was accepted

avatar image
3
Question by SirGive · Jan 11, 2012 at 09:22 PM · android

Android Delta Touch

I think I found an Android bug. Deltatouch seems to be off by about 3 times. This fix allows me to move a few GUI elements at the same pace as my finger. Without *3, my movement lags behind my finger. Here's my fix:

  #if UNITY_ANDROID
         touch.deltaPosition.y *3;
     #else
         touch.deltaPosition.y;

Has anyone else had this issue?

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

3 Replies

  • Sort: 
avatar image
10
Best Answer

Answer by Waz · May 16, 2012 at 10:38 PM

The key is Touch.deltaTime.

The Touch.deltaPosition is the change in position over that time, not over the time of the last frame (the Unity docs are slightly unclear on this, since the events themselves arrived during the last frame). This is why the sum of all Touch.deltaPosition values will not equal the difference between Touch.position values.

You can account for this as follows:

 t.deltaPosition * Time.deltaTime / t.deltaTime

So, the code for dragging a scrollview would be:

 position = GUILayout.BeginScrollView(position);
 ...
 GUILayout.EndScrollView();
 if (Event.current.type == EventType.Repaint) {
   var area = GUILayoutUtility.GetLastRect();
   for (var i=0; i<Input.touchCount; ++i) {
     var t = Input.GetTouch(i);
     var pos = GUIUtility.ScreenToGUIPoint(t.position);
     if (area.Contains(pos)) {
       if (t.phase == TouchPhase.Moved) {
         var delta = GUIUtility.ScreenToGUIPoint(
                t.deltaPosition * (Time.deltaTime / t.deltaTime));
         position += delta;
       }
     }
   }
 }

No need for magic "multiply by 3", nor anything to do with DPI etc.

Comment
Add comment · Show 4 · 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 DavidButtress · Nov 04, 2012 at 01:25 AM 3
Share

Thanks for this, it helped solve my problem, but I also found that Touch.deltaTime will sometimes return zero, so I needed to test for that to avoid a divide by zero.

avatar image mcdon00 · Oct 23, 2013 at 01:56 PM 0
Share

I tried this and it worked well, but when trying it on a different device it was too fast. I first tried it on the Galaxy Tab2 which looked good, then when trying it on the nexus 4 it was too fast.

avatar image Wisteso · Mar 27, 2015 at 06:29 PM 1
Share

The key is not the delta-time. The real issue is the screens having different DPIs. User input should never have delta time used with it unless the input should behave differently based on its speed (like doing more damage for faster swipes). Unity has several known issues with delta time values being reported incorrectly. Its best to avoid using it at all unless you absolutely need to.

Furthermore, Unity does not report DPI correctly with Android devices. This requires you to bypass Unity's bad DPI system and use http://answers.unity3d.com/questions/161281/is-there-a-way-to-android-physical-screen-size.html for Android.

avatar image gdbjohnson · Jun 09, 2015 at 04:42 AM 0
Share

it is interesting to learn that the sum of deltaPosition may not equal the total movement.

avatar image
4

Answer by rutter · Apr 19, 2012 at 08:35 PM

In my somewhat limited experience with Android development, comparing touch `position` between frames can produce more intuitive results than using `deltaPosition` directly.

The fact that they return different values at all seems perturbing, but I can't really comment on the internals involved. ;)

Comment
Add comment · Show 2 · 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 Waz · May 16, 2012 at 10:41 PM 0
Share

The reason they give different results is that Touch.deltaPosition is the change during a specific move event, not during the frame. Indeed, this is why Touch.deltaTime is also given - it is the duration of that move event (otherwise you'd just be able to use Time.deltaTime).

avatar image rutter · May 17, 2012 at 12:12 AM 0
Share

Interesting! Thanks for that explanation. I looked around a little bit, but couldn't find any obvious resource that explains this distinction. Do you know of one, by chance?

I hope this is a decent educated guess: a "move event" is when a touch changes phase, maybe? I guess I can try it and see for myself.

avatar image
2

Answer by dannyskim · Jan 11, 2012 at 10:42 PM

Delta Position of touches is reliant on the phone hardware, thus, it is not uniform across all Android devices.

Typically, a touch screen nowadays takes the capacitance information from a thin and nearly invisible strip of transistors overlaid across your screen in the conductive substrate. This is where the hardware varies, and varies quite vastly in the android atmosphere.

I've always had to have an adjustment multiplier variable to change sensitivity in Android, and I would suggest you give this capability to users if you don't want them complaining about poor controls on Android. This is a widely seen complaint with Android gamers, and it would be wise to take the time and try to smooth it out for as many people as possible.

Comment
Add comment · Show 4 · 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 SirGive · Jan 11, 2012 at 11:00 PM 0
Share

Wow, I did not know that. Thanks!

avatar image Jessy · Apr 19, 2012 at 08:27 PM 0
Share

The hardware may have problems, but deltaPosition is measured in pixels. The variance is due to pixel density.

avatar image SirGive · Apr 20, 2012 at 02:13 PM 0
Share

Jessy, I believe that comment is the entire answer I was looking for on my other question that spanned months.

avatar image Waz · May 16, 2012 at 10:40 PM 2
Share

Don't multiply by magic numbers. This will not work on different hardware, and even on the same hardware may give different results depending on updates and performance changes (so the user would have to keep changing their "speed" setting). See my answer.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Object Despawns/disappears in Android build of game 1 Answer

Unity can't receive information from Intent *urgent 0 Answers

VR (Camera Fov & GearVR) question ! 0 Answers

Facebook SDK login issue with facebook api 0 Answers

Using scripts coded in C# on android projects 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