Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by jimbobuk · Mar 07, 2010 at 03:30 AM · inputiphonetouchspeedswipe

iPhone - How to calculate a decent touch swipe speed?

I'm tracking the touch positions in an update function and am trying to take a measure of the speed of a swipe being performed. At the moment i'm only taking the last frame's touch position change and using this to extrapolate out using Time.deltaTime to get a rough speed of that motion.

I guess i should really be averaging it more than just taking the last frame but i figured it'd at least be ok.

What i'm seeing though seems to be some frames coming through with 0 movement even though the motion is relatively constant speed.

What's going on? Is it because the touches are updated at a certain frequency and the game (at the moment in the simulator and via unity remote) is getting its update frames at a different frequency causing some updates to have not received new touches?

Is there a better callback i can be using that is just updated on touch updates?

Thanks

Comment
Add comment · Show 1
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 Fattie · Mar 17, 2014 at 08:21 AM 0
Share

Full solution and discussion of this difficult problem: http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bampf · Oct 14, 2010 at 04:05 PM

The method you are using is reasonable up to a point. The problems tend to occur if the frame rate is TOO good. You won't see exact pixel movements of 1 or 2 pixels; they tend to get rounded to 0 or 5 pixels. So a tiny movement over a very small deltaTime can be rounded into a 5-pixel movement. When you divide to calculate the velocity, you end up with an absolutely enormous velocity!

A cheap solution is to ignore deltas of less than 10 pixels. That seems to work fine on all the devices I've tested it on, including retina displays. That would probably work for you as well, especially given that you seem to be interested in swipes, not small drags.

To solve your original problem, you could also ignore frames where the movement was 0. But that depends in part on what you are using the velocity for. In my case I wanted to calculate the velocity only when the drag ended. If you need the velocity recalculated throughout the drag you'll probably have to store the last N delta movements and times, and calculate a running average. You'll have to play with different values of N to see what works for your app.

Comment
Add comment · Show 3 · 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 headkitgames · Jan 20, 2011 at 01:38 PM 0
Share

some of us - includingme - are really interested in some bits of code here... thanx!!!

avatar image Bampf · Jan 20, 2011 at 06:06 PM 1
Share

I have a post with code, and a downloadable project, on my blog: http://www.$$anonymous$$dthecube.com/blog/2010/09/adding-iphone-touches-to-unitygui-scrollview In that example I'm dragging around a UnityGUI scrollable area, but the touch and drag detection can be adapted to other things.

avatar image headkitgames · Apr 20, 2011 at 09:07 AM 0
Share

thanx! i will have a look...

avatar image
0

Answer by slek120 · Jan 08, 2014 at 09:18 AM

You can use exponential smoothing on the velocity. smoothVelocity = alpha currentVelocity + (1-alpha) previousSmoothVelocity To calibrate alpha, set it between 0 and 1, 1 being no smoothing. I would estimate something like 0.7.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Joystick Zone + Screen-swipe touch input clash. Solution??? 1 Answer

Detect the direction of a swipe? Touch screen input. 3 Answers

Issue with Input.GetMouseButton (0) on mobile (iPhone) 2 Answers

Input.GetAxis("Vertical") on touch devices. 2 Answers

How to calculate swipe speed on iOS 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