How to implement Swipe controls for mobile?

Hi All, Can anyone please share some of the references for the swipe controls for mobile.

My scenario is as follows :

Swipe Up - The Player should move forward
Swipe Down - The Player should move back
Swipe Right - The Player should move Right
Swipe Left - The Player should move Left

Thanks in advance

Hi @Akhil-Bhaskar,

I don’t have an example with swipe gestures in mind, but you can start with this tutorial:

To calculate a swipe gesture you can calculate the start/end X,Y coordinates that touch input resulted to.

From there calculate the delta between each set of values, for example:

// get delta on X axis
const deltaX = endX - startX;

// a minimum margin to consider this a swipe gesture
const swipeMargin = 100;

// check for swipe right
if( deltaX > 0 && Math.abs(deltaX) > swipeMargin) console.log('swipe right detected');
1 Like