- Home /
Swipe gesture - unable to measure distance
Hello.
I've been having a bit of a problem in my attempt to create proper swipe controls.
This is my script:
var minTouchDistance : float = 500;
function Start () { }
function Update () {
if (Input.touchCount > 0){ var touch = Input.touches[0]; switch (touch.phase){
case TouchPhase.Began:
print("wow, stepping into a new world");
var touchPosition = touch.position;
break;
case TouchPhase.Moved:
print("Just Cruisin");
break;
case TouchPhase.Ended:
var endPosition = touch.position;
var totalDistance = (touchPosition - endPosition).magnitude;
print(touchPosition+" " +endPosition+ " " +totalDistance+ " " + touch.position);
if(totalDistance > minTouchDistance){
//Do stuff
}
print("noooo ! don't untouch meh !");
break;
}
}
}
I realise this script is unfinished, but for now I just want the swiping itself to actuallyw ork - The early print, where I print multiple values, was an attempt to locate the problem. It seems that my original touch position in the "began" case, always returns 0. Which is very weird, while the second value returns the vector 2 value on screen which is fine. But if value 1 is zero at all times, it doesn't seem possible to measure the distance the user has moved from the original point since the original point, no matter where it is, is 0.
Thanks for taking the time to read this, and possibly help me with this issue :)
I'm already using touchphase :P the problem lies in the fact that, at that touchphase, somehow, touch.position returns 0 - Atleast I think that is where the problem lies.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Porting Unity Game to Android 1 Answer
Calculate Distance Between two Game objects 1 Answer
Instantiate a prefab every certain distance while swipping (iOS) 1 Answer
My distance variable is not changing? 2 Answers