Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Calculate swipe speed on Android

Discussion in 'Scripting' started by herbie, May 30, 2015.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    I want to calculate the swipe speed on Android:
    Code (JavaScript):
    1. function Update ()
    2. {
    3.     if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
    4.     {
    5.         speedTouch = (Input.GetTouch(0).deltaPosition.x / Input.GetTouch(0).deltaTime);
    6.     }
    7. }
    But speedTouch becomes Infinity immediately, so Input.GetTouch(0).deltaTime must be zero.
    What am I doing wrong? I know I overlook something stupid.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    in the first frame it will be.... maybe just put a check for deltaTime != 0 in the if?
     
  3. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    No that's not working.
    For some reason Input.GetTouch(0).deltaTime is always zero. So when I put a check for deltaTime != 0 in the if, nothing happens.