Guest User

Untitled

a guest
Dec 10th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // p = current touch point
  2. var p_ : Vector2;
  3. var t_ : float;
  4.  
  5. var velocities : float[] = new float[5];
  6. var i : int;
  7.  
  8. function TouchStart ( p : Vector2 ) {
  9.     velocities = new float[5];
  10.     p_ = p;
  11.     t_ = Time.time;
  12.     i = 0;
  13. }
  14.  
  15. function TouchEnd () {
  16.     velocities = new float[5];
  17. }
  18.  
  19. function Touching( p : Vector2 ) {
  20.     var velocity : float = Vector2.Distance(p, p_) / (Time.time - t_);
  21.  
  22.     i = (i+1) % velocities.length;
  23.  
  24.     velocities[i] = Vector2.Distance(p, p_) / (Time.time - t_);
  25.  
  26.     p_ = p;
  27.     t_ = Time.time;
  28. }
  29.  
  30. function GetAvgVelocity () {
  31.     var avgVelocity : float = 0.0;
  32.     for ( var d : float in velocities )
  33.         avgVelocity += d / velocities.length;
  34.  
  35.     return avgVelocity;
  36. }
  37.  
  38. // sum len(point(t) - point(t-1)) over t  where t = start of touch ... now
  39. // divided by time since start of touch
Add Comment
Please, Sign In to add comment