How can I get the speed of finger drag?
I'm making a mobile game where you control a 3d ball by touch. So far I can get it to roll based on finger down and drag (via TouchPhase.Moved) but I want to be able to detect a fast flick or finger swipe so that I can addforce based on finger speed and let go. Bit like how I would if I was only using TouchPhase.Began and TouchPhase.Ended with calculating start/end position and time duration, but now I think I need to do something in .Moved to keep track of finger speed and get the start and end position of the beginning and end of that fast finger movement. Here's my code so far:
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
touchdown = true;
}
if (touch.phase == TouchPhase.Moved)
{
if (touchdown == true)
{
startPos = new Vector2(0, 0);
}
else {
startPos = Input.GetTouch(0).position;
}
touchTimeStart = Time.time;
direction = startPos - endPos;
timeInterval = touchTimeFinish - touchTimeStart;
endPos = Input.GetTouch(0).position;
touchTimeFinish = Time.time;
rb.AddForce(direction.x * force, 0, direction.y * force/ moveSpeed);
touchdown1 = false;
} if (touch.phase == TouchPhase.Ended)
{
startPos = new Vector2(0, 0);
endPos = new Vector2(0, 0); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613002842im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
First person controls for GoogleCardboard 2 Answers
Trouble carrying over scripted gravity to NPC. 0 Answers
Control Air movement with character controller 0 Answers
Why can my character controlled player can stand on the side of a block? 0 Answers
getting an object to move only along x-axis and y-axis 0 Answers