How to Detect Gestures and Swipes in Godot (tutorial)

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • Learn how to detect touch gestures and horizontal and vertical swipes for your mobile or mouse-based games!
    Get our game creation courses: gdquest.mavens... 🤖
    Beginner Godot course on Udemy: bit.ly/guis-god...
    😄
    Get the final script and an example in Godot Slides 2.0: github.com/GDQ...
    In the /godot-3-presentation/touch_controls folder
    Subscribe for more tutorials! ruclips.net/user/c...
    Twitter ► / nathangdquest
    Instagram ► / nathan_gdquest
    This video is supported by:
    - Gamblify: www.gamblify.com/
    - Pineapple works: pineapple.works/
    - Echo86: www.echo86.com/
    This video is licensed under the CC-By 4.0 license: creativecommon...
    You can attribute it to "GDQuest and contributors - www.gdquest.com/"

Комментарии • 59

  • @TyperMarlinGames
    @TyperMarlinGames 2 года назад +12

    Awesome!
    Just one tip if you're stuck, you need to tick "emulate mouse from touch" in the settings in order for this to work

  • @bruno963852
    @bruno963852 5 лет назад +48

    Very nice! But i would add a little step to detect and exclude very short swipes, just adding a variable called min_distance and checking the distance of the swipe to determine if is bigger than the threshold.

    • @RTSFan1337
      @RTSFan1337 5 лет назад

      Good Idea!

    • @elektroskeptic481
      @elektroskeptic481 4 года назад

      Guys, is there a way to have smooth transition between slides, not this instant one?

    • @elektroskeptic481
      @elektroskeptic481 4 года назад

      @@RTSFan1337 Do you know how to make slides shift smoothly, not instantly?

    • @luisces
      @luisces 2 года назад

      @@elektroskeptic481 You will have to work with the animation player there. I'm necroing this just to post an answer here case anyone else has this doubt. A tut on this can be: ruclips.net/video/x8wgVNN9FsI/видео.html. That's just an example, you can use it for fade effects on scene transitions, etc, etc.

  • @the-birbo
    @the-birbo 2 года назад +5

    I think it might be important to use the "emulate touch from mouse", and also I changed the code so that if the x and y directions are the same, it's not gonna just say i swiped vertically, but rather emit a signal for a click

    • @Silve4
      @Silve4 Год назад

      Can you show me that code? I am trying to implement taping in my game and am having a bit of trouble

    • @the-birbo
      @the-birbo Год назад +1

      @@Silve4 Sure, but first try to work it out with what I've said. If the x direction has the same value as the y direction, emit a custom signal.
      If you're not sure what most of that means, you should learn about if statements and custom signals. If you still need help I'll post my code. try to push yourself 😊

  • @RickoDeSea
    @RickoDeSea 5 лет назад +8

    I love your voice. It makes enjoying the tutorials 10x more.

    • @Gdquest
      @Gdquest  5 лет назад +1

      Thanks for the kind comment 🙂

    • @GAMERMOBILEBRASIL
      @GAMERMOBILEBRASIL 5 лет назад

      I think he has a Brazilian accent, because I'm from Brazil too

  • @kirilvangelovski1255
    @kirilvangelovski1255 4 года назад +2

    Brilliant! Just what I needed and it wasn't going to be easy to figure out.

  • @Watermster
    @Watermster 11 месяцев назад +1

    how would be the "export" code line equivalent to Godot 4? the syntax has changed and I can't get it. Tryed the @export but i get an error "Annotation @export requires at most 0 arguments, but 3 were given.". The code: @export (float, 1.0, 1.5) var MAX_DIAGONAL_SLOPE = 1.3

  • @F4BON3
    @F4BON3 4 года назад

    Guilherme??? different pace, this is much better (for me) than when you are rushing, thank you nice tutorial!!!

  • @rafaelgarcia1435
    @rafaelgarcia1435 4 года назад +5

    And if I want to draw a Line2D using the start and end of the swipe?

  • @ritamch7518
    @ritamch7518 3 года назад +1

    THANK YOU SO MUCH! THIS WAS SO HELPFUL!

  •  5 лет назад +4

    Can something like this be done to control the panning of the camera when the user is dragging or is there a better way to do it?

    • @bittim
      @bittim 5 лет назад +1

      There is, I do it like that:
      pastebin.com/tw00TYEi

  • @mimique_key
    @mimique_key 4 года назад +1

    Hello I realize I’m not sure I understand the math behind the slope and the angle (especially the math vocabulary since english is not my native langage). So I was wondering if anyone could link some ressource about it. Would be really appreciated.
    To add a little bit of context, I tried to readapt the code to be able to handle vertical swipe aswell as horizontal swipe but it wont detect swipe going up but the others directions work. I only changed the maximum slope to 1.5 and the timer to 1 second, nothing else.

  • @xanderul3167
    @xanderul3167 4 года назад

    it's what you need. I wand adaptive this for swipe of mouse, for multi platform game.

  • @SamuelCuster
    @SamuelCuster 5 лет назад +1

    Can you please make a video about how to make UI elements follow the player within the camera? When my player moves, the UI elements don't follow him. I wanted to know if there is a smart way to do this with Nodes. Rather than updating the position of the UI in the process function.

    • @vlusky_husky
      @vlusky_husky 5 лет назад

      canvas layer
      you are making things worse.

  • @glowblock64
    @glowblock64 3 года назад +1

    "This is a bit of text
    And here's some more
    Coloring is going to be a pain in the butt"
    So understandable :P

  • @skullreference9842
    @skullreference9842 2 года назад

    Thanks a lot!

  • @ahjed7397
    @ahjed7397 5 лет назад

    Thanks and n8ce tutorial.
    Pls make how to know touch position in screen to shot to that position.

    • @bittim
      @bittim 5 лет назад +2

      To know where teh Player touched, you just use "event.position" in your _input function. If you want to know the part how to translate the touch position to a position in your game world, here you go:
      pastebin.com/uVgmzKFU

    • @tastelesscivilian9827
      @tastelesscivilian9827 5 лет назад +2

      If its a 3D game you can shoot a raycast from under your cursor

  • @KowixoGD
    @KowixoGD 5 лет назад +2

    And then, how can i detect the swipe , i tried to test with a print but i cant, pls anyone can help me??

    • @takedabro
      @takedabro 3 года назад

      Connect the signal

  • @justdavid6678
    @justdavid6678 Год назад

    please make an updated tutorial

  • @kumarabhinadan1149
    @kumarabhinadan1149 4 года назад

    bro i am messing too much... in your channel there was a playlist that how can we make our first platform 2d game in godot but the problem is how can i do gestures in that game pls help me.....

  • @hs-studio
    @hs-studio 3 года назад

    Guilherme vc é br, vc não me engana 🤣🤣

  • @sosasees
    @sosasees 3 года назад

    Thank you very much for getting me started with the Gesture Controls implementation for my game.
    But when things became clear, I completely branched off from the tutorial (stopped watching it)
    because copying the tutorial as-is for my much more specialized use-case
    (where the gesture detection doesn't need to be nearly as precise)
    would've been Very Stupid because there would've been a lot of stuff in my code that I don't actually need.

  • @tanimsk
    @tanimsk 3 года назад

    WOOW! thanks a lot

  • @libanjustinelowied.1560
    @libanjustinelowied.1560 4 года назад

    Can u please make a tutorial about tilt control in android

  • @whatif674
    @whatif674 2 года назад

    hy eveyone, if i have a button pause, how i know it just press button, i don't wana Swipes now

  • @rohitchalak6379
    @rohitchalak6379 4 года назад +1

    I would like a tutorial on how to detect continuous long touch, for like a hypercasual game. Also if anyone knows where I can get free hypercasual game templates, I will be most grateful.

    • @ritunjoysaikia
      @ritunjoysaikia 3 года назад

      You just don't need the timer I think

  • @Zen-rw2fz
    @Zen-rw2fz 3 года назад

    I can't get the input event to trigger at all. no matter how muhc I touch nothin happens

  • @ac11dc110
    @ac11dc110 5 лет назад

    Nice, now add it as a feature in godot

  • @OlivierPons
    @OlivierPons Год назад

    I cant make this project work under godot 3.5.2

  • @pawelwrzesien5232
    @pawelwrzesien5232 4 года назад

    enable on your pc emualte touch from mouse

  • @shubhijain75
    @shubhijain75 4 года назад

    Which script is used : gdscript or c#

    • @ripzaurus
      @ripzaurus 4 года назад

      Pretty sure it's gdscript. Not sure if you still need this answer.

  • @BuiLderBroz
    @BuiLderBroz 5 лет назад +2

    How to connect it

    • @bittim
      @bittim 5 лет назад +1

      Either with code:
      - In the Script of the SwipeDetector paste this:
      *func _ready():*
      *$Timer.connect("timeout", self, "_on_Timer_timeout")*
      Or Graphically:
      - Select the Timer
      - Click on the "Node" tab next to "Inspector"
      - Click on "timeout()"
      - Click on "Connect"
      - Click on "Connect" again

    • @felipenovais8364
      @felipenovais8364 2 года назад

      @@bittim Still not working.

  • @johnhammer8668
    @johnhammer8668 4 года назад

    Thanks bro

    • @Gdquest
      @Gdquest  4 года назад +1

      You're welcome!

  • @classicguy7813
    @classicguy7813 5 лет назад

    You explain in rigid stiff fierce softness. I didn't like it. LOVE IT

  •  5 лет назад +4

    I found that the mic automatically muting (voice activated) is a bit irritating. I would rather hear some background noise than total silence when you're not saying anything.
    About the content, it looks very useful! Thanks!

  • @BolinhoDeArrozCozido
    @BolinhoDeArrozCozido 5 лет назад

    BR maninho? Nice tutorial!

  • @ciawares
    @ciawares 5 лет назад

    What a version of Godot it is?

  • @stivent0795
    @stivent0795 4 года назад

    No entendí nada

  • @elsam_
    @elsam_ 4 года назад +1

    so how to use it? this is not a noob friendly tutorial hmm :((

    • @takedabro
      @takedabro 3 года назад

      I need it to :((((