- Home /
Move with finger ?
Hello, i'm trying to make a game where the player (at the center of the screen), move when we swipe. For example, if we swipe left the player move 100px on the left (when we stop touching the screen).
So I have something like this:
public Vector2 startPos; public Vector2 endPos;
public Vector2 direction;
public bool directionChosen;
void Swipe() { //----SWIPE---- if (Input.touchCount > 0) { var touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
startPos = touch.position;
directionChosen = false;
break;
case TouchPhase.Moved:
direction = touch.position - startPos;
break;
case TouchPhase.Ended:
endPos = touch.position;
directionChosen = true;
var Z = direction.y;
Player.transform.Translate( direction.x /10, 0, Z /10, Space.Self);
break;
}
}
}
As you figure, it's not what i really intended, the precision isn't there. And it looks like a teleportation instead of a dash on a direction (maybe because the translate is on the Ended. Could you help me. Thanks.
Your answer

Follow this Question
Related Questions
Swipe Android 1 Answer
Add limitation in Finger gesture package for touch 0 Answers
PDollars & Line renderer 0 Answers
Trail Rendering 0 Answers
Need help getting my character to move 2 Answers