|Topic was automatically imported from the old Question2Answer platform.
Hey, I am new in godot, I want to know how can I control my character ( an area2D) by swipes, I’m making a game for android, in the game the character will be moved by swipes, for example if I make a gesture like drag down my character it would jump, if I drag in a diagonal direction it would get shot to de oposite side, it’s like when you’re going to launch the bird in angry birds, you swipe and the bird get shot to the pigs. If anyone knows how to do it pleaseee heeelp!
Touch gestures work similarly to mouse movement. So to detect finger dragging or similar swipes, you may be able to use this code:
var dragging = false
var tap_radius = 32 # Size of the sprite
if event is InputEventScreenTouch:
if (event.position - $Sprite.position).length() < tap_radius:
# Start dragging if the click is on the sprite.
if !dragging and event.pressed:
dragging = true
# Stop dragging if the button is released.
if dragging and !event.pressed:
dragging = false
if event is InputEventScreenDrag and dragging:
$Sprite.position = event.position
I haven’t tried this code, so it may not work for you. Also look at this post for helping in detecting taps and drags. And for even more info on inputs, look to the Input Examples article in the official documentation.
Ertain | 2020-04-12 19:12