0 votes

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! :(

asked Apr 12 in Projects by Angel (14 points)

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

func _input(event):
    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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.