Godot 3 - Multitouch (Tutorial)

Поделиться
HTML-код
  • Опубликовано: 1 фев 2025

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

  • @iaknihs
    @iaknihs  2 года назад +8

    This was way too long in the making. This weird 'life' thing kept interrupting me.
    Anyhow, I somehow got past 1k subs now. 🤔🥳 Thanks for watching!
    For any ideas, questions, improvements, etc. - leave a comment ;)

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

      Do you how to change languages in a game? Like, having all the texts in a database and then switching between languages

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

      @@abdiel3358 Text-translations will usually be handled using spreadsheets (specifically, comma-separated-value files [.csv])
      You have a column for keys, and then one column each per language.
      Then you can import this .csv into godot (project settings > localization) allowing you to access them in code.
      For more details, you can also take a look at the "importing translations" and "internationalizing games" in the Godot docs.

  • @boxerliso4855
    @boxerliso4855 7 месяцев назад +2

    Gracias, hermano!! Estoy haciendo un juego en mi celular y por fin pude saber cómo hacerlo. 😺

  • @Pulkz
    @Pulkz 2 года назад +1

    Love ur Tutorials mate

  • @kathe5664
    @kathe5664 2 года назад +1

    Thanks for the new wonderful tutorial video 💜

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

      Very welcome, glad you liked it!

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

    That's what I needed, Thank you so much :)

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

    Continue making Godot known with your videos 👍

  • @adammekla5465
    @adammekla5465 9 месяцев назад

    Thank you. That was very helpful.

  • @Ocape
    @Ocape 2 года назад +1

    How can i make gun (look at) with mobile control like if i touch the screen the gun look at where i touched please i need to know

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

      Do you mean a 2D game or 3D?
      In 2D it's easy, just get the touch coordinates and rotate the gun towards that. (can find the math for it on google pretty quick)
      In 3D you need to first determine what you actually touched. So a raycast from the touch position at the camera to whatever object would be "straight ahead" from there. That's a fair bit more complex o=

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

      @@iaknihs how? been struggling to find the mobile aim 2D for days(weeks now), I need to calculate joystick pos and rot somehow

  • @capuchinosofia4771
    @capuchinosofia4771 9 месяцев назад +2

    the code is in a pretty small font and is hard to read what you wrote down but besides that, very good tutorial!

    • @capuchinosofia4771
      @capuchinosofia4771 9 месяцев назад +1

      for future hard-sighted people:
      This is the first part code:
      extends Node2D
      var down =[]
      func _input(event):
      if event is InputEventScreenTouch:
      if !event.pressed:
      down.erase(event.index)
      elif is_in_rect(event.position, $CanvasLayer/TextureButton.get_rect()):
      down.append(event.index)
      $CanvasLayer/Label.text= str(len(down))

      func is_in_rect(pos, rect):
      return pos.x > rect.position.x \
      and pos.y > rect.position.y \
      and pos.x < rect.end.x \
      and pos.y < rect.end.y \

    • @capuchinosofia4771
      @capuchinosofia4771 9 месяцев назад +2

      well, after some trial and error I have to give up on the second part of the tutorial (camera zoom by pinch). Maybe its my godot version? Im using 3.5.2.
      I used tons of print statements and it seems that only pos 0 is registered while pos 1 is nowhere to be found (not even the "everything is false for pos 1" print is printed. Any idea why?
      Code:
      extends Node2D
      const zoom_speed = 0.005
      const zoom_min = 0.25
      const zoom_max = 4.0
      var pos_0 : Vector2 = Vector2.ZERO
      var pos_1 : Vector2 = Vector2.ZERO
      var pos_0_valid: bool = false
      var pos_1_valid: bool = false
      var pos_0_moved: bool = false
      var pos_1_moved: bool = false
      var distance_prev = 0
      var distance_prev_valid = false
      func _input(event):
      if event is InputEventScreenTouch:
      if event.pressed:
      match event.index:
      0:
      pos_0 = event.position
      pos_0_valid = true
      print("pos0 is valid")
      pos_0_moved = false
      1:
      pos_1 = event.position
      pos_1_valid = true
      print("pos1 is valid")
      pos_1_moved = false
      else:
      #set position as invalid
      match event.index:
      0:
      pos_0 = Vector2.ZERO
      pos_0_valid = false
      pos_0_moved = false
      distance_prev_valid = false
      print("everything is false for 0")
      1:
      pos_1 = Vector2.ZERO
      pos_1_valid = false
      pos_1_moved = false
      distance_prev_valid = false
      print("everything is false for 1")
      elif event is InputEventScreenDrag:
      match event.index:
      0:
      pos_0 = event.position
      pos_0_moved = true
      print("pos0 is moved")

      1:
      pos_1 = event.position
      pos_1_moved = true
      print("pos1 is moved")

      func _process(_delta):
      #pinch/zoom
      if pos_0_valid and pos_1_valid and (pos_0_moved or pos_1_moved):
      print ("zoom conditions have been met")
      var distance: float = pos_0.distance_to(pos_1)
      if !distance_prev_valid:
      distance_prev = distance
      distance_prev_valid = true
      else:
      print("camera should be adjusting")
      #adjust camera zoom value
      var dist_change = distance - distance_prev
      $Camera2D.zoom.x = clamp($Camera2D.zoom.x - dist_change * zoom_speed, zoom_min, zoom_max)
      $Camera2D.zoom.y = $Camera2D.zoom.x

      distance_prev = distance

  • @redsam4538
    @redsam4538 2 года назад +1

    Big thanks! I'm working on a project that needs touch inputs. I've just figured how to solve my problem while I was watching this vid. Idk if its a bug, but the first multitouch example doesn't work if you handle it from a control' gui_input signal; because it doesn't detect touch release when there is multiple fingers.

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

      Hey, have you tested different cases for that issue?
      Does it only miss the release signal after moving fingers, or always?
      Sounds to me like either the signal isn't made to account for multitouch (so gotta manually keep track of fingers like in the video), or it only fires if a finger is released on the same gui element. Can't test right now, but seems like a interesting thing to try.

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

      @@iaknihs the exact piece of code that you showed on the video works in the _input method but doesn't in a gui_input callback. A release input is only fired when all fingers are up. Must be a bug, we should open an issue if its the case

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

      @@iaknihs after retesting, it fires a release only when the first finger is up, whether it has moved or not

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

      @@redsam4538 fascinating, yeah I don't see this mentioned in the documentation at all so seems like a bug indeed. Which version are you using?

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

      @@iaknihs v3.4.2

  • @level8208
    @level8208 2 года назад +1

    Hello! How to adapt this to drag to separate objects? Like one finger for 1 apple

    • @iaknihs
      @iaknihs  2 года назад +1

      When clicked, the object would have to save the index of which finger clicked it. Then while sliding it can move to whichever position that index has now. When the finger is lifted, the object can forget the id again

  • @PHDtt
    @PHDtt 11 месяцев назад

    is it possible to make a tutorial for 3D scene ?

  • @digitalpotato4867
    @digitalpotato4867 2 года назад +1

    The touch funcions for Android, do you think would export for Linux x64? I have a phone and Tablet, and I'm not quite sure that the touch functions might not be usable if godot exports for Linux desktop

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

      That's a tough one, I don't have any touch devices I could run Linux on so I can't actually test it. Theoretically the engine *should* recognize touch inputs from all platforms where export templates exist, but there are always edge cases where it's going to fail so if you find it doesn't work it's probably best to report as a bug to the godot devs

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

      @@iaknihs if it works under html5 or webgl in your phone, you're ready to export to Linux with the pck is enough. I can do the rest of the me magic

  • @lordav5520
    @lordav5520 11 месяцев назад

    I have a question. Do you can made joystick with a character 2d with a grid o with a 32x32 pixels ? Thank you

  • @question_mark
    @question_mark 2 года назад +2

    lezgoooo

  • @Error-Free-Solutions
    @Error-Free-Solutions Год назад

    why screen dragging not working