Swipe detector

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By melka24


I would like to learn how to make mobile games. The game I’m working on is using swipe detection. After watching some tutorials I put together this code:

var swipe_start = null
var minimum_drag = 100

func _unhandled_input(event):
if event.is_action_pressed("click"):
    swipe_start = event.get_position()
if event.is_action_released("click"):

func _calculate_swipe(swipe_end):
  if swipe_start == null: 
  var swipe = swipe_end - swipe_start
  if abs(swipe.x) > minimum_drag:
    if swipe.x > 0:

This code should determine if the user swiped and in which direction (left or right). Also, in the Input Map I chose “click” to be left mouse click.

The game works when I’m playing on my laptop (I click and drag with mouse) so I published it on google play but when you play the game on phone the swipe detector doesn’t work.

Any ideas

:bust_in_silhouette: Reply From: rustyStriker

Try setting emualte mouse(or something like that) in the project settings.

beside, you can use _input(event) function and InputEventScreenTouch + InputEventScreenDrag to get swipes for your game(i used it and got some touch joysticks working and some nice things in my android game)