Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // p = current touch point
- var p_ : Vector2;
- var t_ : float;
- var velocities : float[] = new float[5];
- var i : int;
- function TouchStart ( p : Vector2 ) {
- velocities = new float[5];
- p_ = p;
- t_ = Time.time;
- i = 0;
- }
- function TouchEnd () {
- velocities = new float[5];
- }
- function Touching( p : Vector2 ) {
- var velocity : float = Vector2.Distance(p, p_) / (Time.time - t_);
- i = (i+1) % velocities.length;
- velocities[i] = Vector2.Distance(p, p_) / (Time.time - t_);
- p_ = p;
- t_ = Time.time;
- }
- function GetAvgVelocity () {
- var avgVelocity : float = 0.0;
- for ( var d : float in velocities )
- avgVelocity += d / velocities.length;
- return avgVelocity;
- }
- // sum len(point(t) - point(t-1)) over t where t = start of touch ... now
- // divided by time since start of touch
Add Comment
Please, Sign In to add comment