Implementing a gesture
Another type of input that you'll find in mobile games is that of a swipe. This will allow us to use the general movement of the touch to dictate a direction for us to move in. This is usually used to have our players jump from one position to another or move quickly in a certain direction, so we'll go ahead and put that in, instead of our previous movement system:
- First, in the
PlayerBehaviour
script, go ahead and add some new variables for us to work with:
[Header("Swipe Properties")] [Tooltip("How far will the player move upon swiping")] public float swipeMove = 2f; [Tooltip("How far must the player swipe before we will execute the action (in pixel space)")] public float minSwipeDistance = 2f; /// <summary> /// Stores the starting position of mobile touch events /// </summary> private Vector2 touchStart;
In order to determine whether we are swiping, we will need to first check the start and the end of our movement...