How to add Mobile JOYSTICK in Godot 3? Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 พ.ย. 2024

ความคิดเห็น • 106

  • @Nyltoons1
    @Nyltoons1 ปีที่แล้ว +4

    Straight forward tutorial and very easy to implement, got mine working after just following this.
    Side note if you want to use this and have action button on the other side of the screen.
    func _input(event):
    if event is InputEventScreenTouch or event is InputEventScreenDrag:
    if event.position.x>(half of screen size):
    return
    move_vector=calculate_move_vector(event.position)
    the "if event.position.x>(half of screen size): return" will cancel out any touch input on the other half so that the analog controller will keep on applying to the movement.
    Cheers Rafa Fiedo!!!

    • @RafaFiedo
      @RafaFiedo  ปีที่แล้ว

      nice:)
      For sure that will be helpful! :)

  • @Sas-l4h
    @Sas-l4h 9 หลายเดือนก่อน +2

    Величезне дякую ❤

    • @RafaFiedo
      @RafaFiedo  9 หลายเดือนก่อน +1

      no problem ;)

  • @gaminggamma2875
    @gaminggamma2875 3 ปีที่แล้ว +7

    I really needed this

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      You're welcome! :D

  • @DestusG
    @DestusG 2 ปีที่แล้ว +5

    Awesome tutorial. I got lost a bit but found my way back thanks for making this

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว +1

      that's great!
      Could I ask in which part you were confused?

    • @DestusG
      @DestusG 2 ปีที่แล้ว +2

      @@RafaFiedo also I'm still working on it to make it work on stuff like rotation for example if you want the event.position = weapon.rotation (stuff like that). I've already done that before using the old joystick plugin i was using but i prefer yours cause the code is simple and easy to understand. So thanks for making this tutorial again

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว +1

      Great to hear that explanation was useful :D

  • @cherryblossoms5970
    @cherryblossoms5970 2 หลายเดือนก่อน +1

    that one is well explained. Thank you.

  • @afksystem6245
    @afksystem6245 3 ปีที่แล้ว +3

    Most expected video❤️

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +1

      Hope it was worth waiting ;)

  • @myprofile1379
    @myprofile1379 2 ปีที่แล้ว +3

    Thank You So Much You Explained It With Less Complexity

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      Thanks for the feedback!

  • @42Mrtoxa42
    @42Mrtoxa42 2 ปีที่แล้ว +2

    Thank you is great a for my project!

  • @aladinbaniel7563
    @aladinbaniel7563 3 ปีที่แล้ว +11

    It has a bug.. if you press on the other side of the screen while using the joystick, it will register as a new touch input and your move direction will be affected

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +6

      You're right :)
      Didn't tested that people will use 2 fingers for joystick.
      One of simple solution is to limit the range of the input (for example only left side of the screen) or use the index of the touch events.
      Thanks for the feedback!

    • @aladinbaniel7563
      @aladinbaniel7563 3 ปีที่แล้ว +8

      @@RafaFiedo yep.. fixed it by using the index of touch events

    • @2eea5y70
      @2eea5y70 2 ปีที่แล้ว +3

      @@aladinbaniel7563 hi bro
      can you show me the code to fix it
      im stuck at this point

    • @onurozel5765
      @onurozel5765 2 ปีที่แล้ว +1

      @@RafaFiedo thank you! could you explain how to use touch index?

  • @wash99
    @wash99 3 ปีที่แล้ว +5

    Thanks
    You're tutorials are fun to watch

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      Glad you like them! :D

  • @omslakajacka
    @omslakajacka 2 ปีที่แล้ว +6

    Simple & useful... Even works in Godot 4! 💛

    • @max_mohan_2.0
      @max_mohan_2.0 ปีที่แล้ว

      My Script Shows "The Math "Calculate Move Vector" Isn't declared in the current class." It's Godot 4 Beta 8.

    • @10Dima01
      @10Dima01 6 หลายเดือนก่อน

      is it really works in Godot 4.2.1?
      I can't make it works

  • @andru8201
    @andru8201 ปีที่แล้ว +1

    thank u so much, u saved my life

    • @RafaFiedo
      @RafaFiedo  ปีที่แล้ว

      Glad that it helped!

  • @vinaciotm
    @vinaciotm 2 ปีที่แล้ว +2

    very good explain

  • @AcroProjects
    @AcroProjects 3 ปีที่แล้ว +5

    Thank you so much! This was really helpful! I have a question about the inner circle. Not sure if I'm gonna explain this well, but I noticed since the inner circle is following the "event position", the inner circle will move to anywhere on the screen as long as you touch the touchscreen button first. How can I keep the inner circle from leaving the outer circle's boundaries?

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +7

      Glad it was helpful Acro Projects!
      Ye, I understand that issue.
      Making long story short... You need to calculate the "limit" vector from middle of the texture
      pseudocode:
      if center_texture_position.distance_to(event_position) > big_circle_radious:
      var calculate_new_vector = normalized_vector * big_circle_radious
      $InnerCircle.position = center_texture_position + calculate_new_vector
      else
      $InnerCircle.position = event_position
      function which can you use: (as a homework you can try predict where to use it :P)
      func limit_the_inner_circle(event_position):
      var texture_center = $TouchScreenButton.position + Vector2(64,64)
      var limit = 64 #in pixels
      if texture_center.distance_to(event_position) > limit:
      var limit_vector = move_vector * limit
      $InnerCircle.position = texture_center + limit_vector
      else:
      $InnerCircle.position = event_position
      $InnerCircle.visible = true
      btw. Would you be interested in "Basic 2d algebra in Game Dev" video?

    • @AcroProjects
      @AcroProjects 3 ปีที่แล้ว +1

      @@RafaFiedo Thank you so much! A "Basic 2d algebra in Game Dev" video would be awesome to see and really helpful =)

    • @daampew2701
      @daampew2701 3 ปีที่แล้ว +1

      oh, hi, i have the same question. i put the "func limit_inner_circle in the _input func" but still feels like busy/sticky. the center button turns back to the center. ty!

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +1

      @@daampew2701 Does the pixel size are the ok? Maybe you are using higher resoltion

    • @fruitdudetv
      @fruitdudetv 3 ปีที่แล้ว

      @@RafaFiedo mh.. the "limit_the_inner_circle" function does not work at all for me. can still drag the "InnerCircle" everywhere i want. i put the function call inside the "if $OuterCircle.is_pressed():" statement.

  • @rounak3811
    @rounak3811 3 ปีที่แล้ว +3

    The Lord of the rings :
    The return of the Phone 😂

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      haha, great title! :D

    • @gelosoor4281
      @gelosoor4281 3 ปีที่แล้ว +1

      Love lotr ☺️🤣🤣🤞

  • @hazeebx
    @hazeebx ปีที่แล้ว +3

    In Godot 4, move_and_slide no longer takes parameters so I wrote:
    velocity = move_vector
    move_and_slide()
    inside the signal call function but it isnt working.
    Also I tried printing move_vector value from inside the signal and it outputs (0,0) always regardless of joystick movement. Even though when I run just the MobileJoystick scene, and try to print move_vector, it gives the appropriate coordinates according to movement.
    pls help

    • @lapusanmirel5707
      @lapusanmirel5707 ปีที่แล้ว

      You have to do it inside _physics_process(delta): which is called like 60 times a second should like something like :
      func _physics_process(delta):
      velocity = move_vector * movement_speed
      move_and_slide()
      Also for signals to work your player character needs to have an instance in the same tree as the touch button or else signal wont connect. I suggest using a SignalBus which can be called from wherever.

  • @itsME-dc4vm
    @itsME-dc4vm 3 ปีที่แล้ว +3

    nice ;D

  • @omslakajacka
    @omslakajacka 2 ปีที่แล้ว +1

    Please continue new tutorials with Godot 4 🙏🏼

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว +1

      no promises, but... maybe I will :D

  • @gelosoor4281
    @gelosoor4281 3 ปีที่แล้ว +2

    Thanks for this video
    I ask if you can make more tutorials about moba hero
    Talking more about particles and the map with tilesets that well be very good if you make a tutorial about it

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +1

      Hi GeLo! Thanks for the feedback :)
      Thanks for the propositions!
      That make me thing about making a new poll tutorial about what to do next.
      Maybe a fast tutorial about how to make auto-tilemap is good idea. The bad side of this is that will be outdated in near future as the Godot 4.0 will have new tilemap system

    • @gelosoor4281
      @gelosoor4281 3 ปีที่แล้ว

      @@RafaFiedo lol just want to know when did this highly update come to godot lol thanks for thinking in the idea
      I hope you be the best
      Good luck 🤞

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +1

      haha, I also would like to know, but it's looking promising :)
      for example here is one of the progress report
      godotengine.org/article/tiles-editor-progress-4

    • @gelosoor4281
      @gelosoor4281 3 ปีที่แล้ว +1

      @@RafaFiedo oh it's sounds more interesting after I read this article

  • @peeleandro
    @peeleandro 2 ปีที่แล้ว +2

    Can you do that for 3d too?

  • @pistachoduck9128
    @pistachoduck9128 3 ปีที่แล้ว +2

    Phone came back, Let's GOOOOOOOO!!!!!

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +1

      Pure magic ;)

  • @Yokulovescake
    @Yokulovescake ปีที่แล้ว +1

    What if I want a weapon to rotate according to the joystick

  • @poiter6093
    @poiter6093 3 ปีที่แล้ว +3

    Hi, could you make maybe a health and damage tutorial?
    When the player hit a object it will give damage to the player.

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว +2

      Hi Prince Of Bel-Air!
      Sound like a nice tutorial idea, thanks!
      In the meanwhile you can check the "How to do Enemy AI 2D - melee attack", I show there the PlayerDetector logic and the "How to do health bar" to display HP bar.
      Full list you can find on the github.com/rfiedorowicz/GodotProjects

  • @brianbatton9950
    @brianbatton9950 3 ปีที่แล้ว +3

    Thank you for this :)

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      My pleasure!
      Few days ago I read again your discuss with OSIRIS on the comment about Joystick :)

    • @brianbatton9950
      @brianbatton9950 3 ปีที่แล้ว +1

      @@RafaFiedo Haha thank you so much this really helped!

  • @МаксАксиом-к7ю
    @МаксАксиом-к7ю 3 ปีที่แล้ว +3

    Hi,I am the same Pomponchik))🍩

  • @ennizodev
    @ennizodev 3 ปีที่แล้ว +2

    That's what I looking for 😭😭😭😭

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      Happy that you found it :D

    • @ennizodev
      @ennizodev 3 ปีที่แล้ว +1

      @@RafaFiedo ^^ yes, always success bro🙏🏻

  • @ellibistayan3208
    @ellibistayan3208 7 หลายเดือนก่อน +1

    Why your output on 2:32 of the video was normalize? I carefully follow your step. Plseas help.

    • @RafaFiedo
      @RafaFiedo  7 หลายเดือนก่อน +1

      normalized vector has a length = 1, in this way it is easy to calculate vector length = RADIUS size. You can use this vector (with radius size) to get good position on the circle.
      Hope that helped ;)

    • @ellibistayan3208
      @ellibistayan3208 7 หลายเดือนก่อน +1

      @@RafaFiedo woah, thank you very much at your reply I really appreciated it. I will use your recommendation. I hope you may succeed :)

    • @RafaFiedo
      @RafaFiedo  7 หลายเดือนก่อน

      ​:D

  • @braveblade87
    @braveblade87 2 ปีที่แล้ว +2

    I have an error (The function 'move_and_slide()' returns a value, but this value is never used.)
    Very nice tutorial btw.

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว +3

      Thanks :)
      Are you sure is a error? It looks like a warning.
      More about move and slice you can find on my "how to move_and_slide" tutorial ;)

  • @SemperFidelisGames
    @SemperFidelisGames 2 ปีที่แล้ว +1

    Can I get the Dithering preset you used on your carpet?

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      What is a "Dithering"? :D

  • @thechargedone169
    @thechargedone169 2 ปีที่แล้ว +1

    Hey man, idk if you will see this but ive got a problem. The moment when i pot the emit signal into the physics process, it just wont send a signal again. Could you help me please

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      Hi!
      You said that it won't send a signal again. So you have situation when the signal is just working once, right?

    • @thechargedone169
      @thechargedone169 2 ปีที่แล้ว

      @@RafaFiedo hello, thanks for the reply but i figured it out at the end. but i wanted to ask if it was possiblr to make the joystick control the speed too, meaning if the joystick is more in the center, the speed is less and the further fron the center, the faster you go. i think i explained well😅

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      Yup, it is possible :D
      Try to use the vector from 'event_position - texture_center'
      On the video I just normalize it (so it will be always 1.0).
      You can remove normalization and play with parameters (probably you will need to divide that vector)

    • @thechargedone169
      @thechargedone169 2 ปีที่แล้ว +1

      @@RafaFiedo ah cool i just figured it out, thanks alot you got a new sub

  • @ProAxiz
    @ProAxiz 3 ปีที่แล้ว +1

    how to get the joystick angle?

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      just use .angle() method for move_vector ;)
      more about it you can find on documentation docs.godotengine.org/en/stable/classes/class_vector2.html#class-vector2-method-angle

  • @sergiopineros2012
    @sergiopineros2012 3 ปีที่แล้ว +3

    Hello, when I instantiate the CanvasLayer to the player and add the code (from minute 3:14) I get the following error: The method "move_and_slide" isn´t declared in the current class. I am new to all this, I really appreciate if someone can help me.😀

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      hey Sergio!
      What do you have on the first line of your script?

    • @sergiopineros2012
      @sergiopineros2012 3 ปีที่แล้ว

      @@RafaFiedo Hello, thank you very much for your answer, in the first script line I have "extends Area2D", I have changed it to "extends KinematicBody2D" and it throws me: script inherits from native type kinematicbody2d, so it can't be instanced in object of type: ' Node 'Thanks again

    • @RafaFiedo
      @RafaFiedo  3 ปีที่แล้ว

      @@sergiopineros2012 Try to connect script to KinematicBody2D node :)

  • @ALIAli-di8ph
    @ALIAli-di8ph ปีที่แล้ว

    How do I make the little one not come out from touching the screen when I move it?

    • @RafaFiedo
      @RafaFiedo  ปีที่แล้ว

      you need to calculate length of the vector between center of texture and 'InnerCircle' and limit it ;)

    • @ALIAli-di8ph
      @ALIAli-di8ph ปีที่แล้ว

      ​@@RafaFiedoCan you write it in code format because I am an Arab and I did not understand even when I translated your response because I did not understand and thank you🇮🇶❤

  • @Ocape
    @Ocape ปีที่แล้ว

    How to make joystick for shooting

  • @Sykoシ
    @Sykoシ 2 ปีที่แล้ว

    I have problem with emit_signal it's say
    "emit_signal: can't emit non-existing signal "use_move_vector"

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      Do you still have that issue?

  • @intrusivethoughts3601
    @intrusivethoughts3601 ปีที่แล้ว

    3:39 this didn't work, it still just stops moving when I stop sliding my finger

  • @chenpead
    @chenpead 7 หลายเดือนก่อน

    it says an error like too many arguments for move and slide. expected 0 but its 1

    • @RafaFiedo
      @RafaFiedo  7 หลายเดือนก่อน

      i suppose that you are using Godot 4, yes?
      Few things changed since godot 3 which I am using for this tutorial

    • @chenpead
      @chenpead 7 หลายเดือนก่อน

      @@RafaFiedo yeah im using 4

    • @chenpead
      @chenpead 7 หลายเดือนก่อน +1

      @@RafaFiedo i fixed the problem by using ai, everything is working good except my characters movements kinda dont match the joystick like u showed on ur video

    • @RafaFiedo
      @RafaFiedo  7 หลายเดือนก่อน

      @@chenpeadyou can share more details like 'video' of your state on our discord, maybe we could help ;)

    • @chenpead
      @chenpead 7 หลายเดือนก่อน +1

      @@RafaFiedo i finally solved it but ill definitely join ur discord server because ur channel is so useful and good

  • @elninoyoutube3418
    @elninoyoutube3418 4 หลายเดือนก่อน

    Podrias hacer tutorial en español o un canal tuyo en español porque pareces que explicas bien pero como esta en ingles casi no entiendo😅

    • @RafaFiedo
      @RafaFiedo  4 หลายเดือนก่อน

      at first I would need to learn a Spanish xD
      But that could be a nice challange

  • @2eea5y70
    @2eea5y70 2 ปีที่แล้ว

    can someone help me to set index of touchscreen to 1 , so it wont affect register as a new touch

    • @RafaFiedo
      @RafaFiedo  2 ปีที่แล้ว

      What exacty is the issue? :)

  • @potatohot656
    @potatohot656 ปีที่แล้ว +1

    thanks