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
2
Question by bakedlama · Mar 06, 2015 at 02:56 AM · androidunity 5bugtouchdelta

Touch.deltaPosition giving jerky movement on Android in Unity 5

I'm working on a game where the character is controlled very simply by touching and dragging anywhere on the screen. Since upgrading to Unity 5, the character will randomly speed up and slow down, at times appearing to teleport across the screen even though I'm dragging my finger at a relatively constant speed.

The simplest version of the code looks like this:

 void Update() {
   if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Moved) {
     Touch touch = Input.touches[0];
     Vector3 t = new Vector3(touch.deltaPosition.x * 10f * Time.deltaTime, touch.deltaPosition.y * 10f * Time.deltaTime, 0.0f);
     gameObject.transform.Translate(t);
   }
 }

(In my game, I've replaced the "10f" values with an adjustable "sensitivity" setting.)

That's the code that was working in my 4.6 project. Since looking into this issue, I found one suggestion to check against Touch.deltaTime, which makes the code look like this:

 void Update() {
   if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Moved)
   {
     Touch touch = Input.touches[0];
     float dt = Time.deltaTime / touch.deltaTime;
     if (dt == 0 || float.IsNaN(dt) || float.IsInfinity(dt))
       dt = 1.0f;
     Vector2 fixedTouch = touch.deltaPosition * dt;

     Vector3 t = new Vector3(fixedTouch.x * 10f * Time.deltaTime, fixedTouch.y * 10f * Time.deltaTime, 0.0f);
     gameObject.transform.Translate(t);
   }
 }

However, that didn't seem to have any effect -- at least, it didn't solve my issue. I've created a new 2D project which contains only the default Main Camera and a Sprite, to which I've attached the script above. I can't find any combination of settings that stops the sprite from moving erratically when I drag it around the screen.

I'm testing this on a Nexus 5 running Android version 5.0.1. When I upgraded to Unity 5 I had to upgrade my JDK, but this doesn't seem to be the cause of the issue as the sprite moves smoothly after creating exactly the same test project in Unity 4.6. One thing I did notice is that the deltas seem larger in 4.6, so that I had to lower the "10f" to "5f" to get the sprite to move at approximately the same speed so I could watch it for jerkiness without it jumping off-screen.

So, with that final test -- exactly the same simple project running in 4.6 and 5.0 -- I think I'm safe adding the "bug" tag to this post. However, I'm relatively new to Unity, so my questions are:

  • Am I doing anything wrong in my code?

  • Has anyone else seen this issue? Can you reproduce it on other Android devices / iPhones / etc.?

  • Can you think of anything for me to try?

  • Is there any other information I should include in my bug report?

I'll go ahead and file a proper bug report, but I figured I would post this here to see if anyone else is experiencing this as well. Oh, and let me know if this isn't the right place for this as I'm on the fence about whether to post this to Answers or the Forums! Thanks for your help!

Comment
Add comment · Show 2
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 meat5000 ♦ · Mar 06, 2015 at 02:56 AM 1
Share

It may fit both here and forum but crossposting isnt really allowed.. Lets give it a go.

avatar image pep_dj · Mar 06, 2015 at 06:56 PM 1
Share

I'm having the same issue. I noticed that deltaPosition is not giving correct value for each update loop (sometimes is giving 0 ins$$anonymous$$d of the correct value). It was working perfectly on 4.6.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by PedroGV · Mar 13, 2015 at 12:35 AM

Similar situation here.

EDIT: one of the things I notice is that values tend to be correct as the touch approaches to the center of the device's screen.

This used to work fine on Unity 4.6 so it is definitely a bug in Unity 5.

I've just opened a thread about this in the forums: http://forum.unity3d.com/threads/touch-deltaposition-giving-odd-values-on-android-unity-5.310422/

Bug reported here: http://fogbugz.unity3d.com/default.asp?680416_onmc6vehavpdkpuh

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
avatar image
1

Answer by theH00b · Dec 15, 2015 at 09:49 PM

I'm using touchcontrols to drag and zoom a 3d camera over a flat worldmap. I had the same problem with jerky and unreliable controls using deltaPosition and deltaTime and in the end I changed my code to compare the current touch position with the position at the start of the drag. This works perfectly for me.

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

6 People are following this question.

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

Related Questions

In-App-Purchases not working (Android) 1 Answer

How to select gameobjects on android by touching on them? 1 Answer

Infuriating bug: Android build occasionally dropping touch input. 0 Answers

Android Touch Input works perfectly on Samsung Galaxy S3 but breaks on Galaxy S4 0 Answers

Unity Bug, Letting User To touch two UI Buttons as same time (simultaneously) 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