Joystick in Godot [in 3 minutes]

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • brrrrr....
    Hew to mak a joystik in Godot :)
    Dat forum post : godotengine.or...
    Godot : godotengine.org
    Background Music : • Video [its good]
    These guys also made video about Joysticks in Godot...check them out:
    -Godot 3: How to make a Joystick [Gonkee]
    --- • Video
    -How to add Mobile JOYSTICK in Godot 3? Tutorial [Rafa Fiedo]
    --- • How to add Mobile JOYS...
    About me:
    Hey , i am Mokarrom Hossain , a student with a hobby of learning odd stuffs
    Currently interested in Game Development and also a bit of music
    I try to upload regularly [i know i am irregular .. hehe] .. I read all the comments, at least i try to read them all...and...umm....yeah....that's all i guess....bye...
    Subklibe -_-
    #chibituts #godot #gamedev

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

  • @MokarromHossain
    @MokarromHossain  ปีที่แล้ว +24

    ⚠⚠⚠
    This code is kinda buggy so it would be a okay-ish solution for simple one joystick project
    but for a serious project or if you need a better joystick then i guess you should use a plugin...
    ❤⬇⬇
    Thanks to @rocket007 for finding this plugin
    Virtual Joystick by MarcoFazio : godotengine.org/asset-library/asset/398

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

      Thanks for mentioning me here, much appreciated =D

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

      Sorry @goreldeen , I didn't make the plugin!, I just found it and recommended it as it was what i used in my own project.
      Credits to the original creator: MarcoFazio

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

      @GorEldeen the original creator is MarcoFazio

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

      Thank you

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

      ​@goreldeen look who I found!

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

    This is the most useful tutorial I've ever seen

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

    great tutorial! for those using godot 4, onready vars didnt work so, while this is sorta bad practice, I just redeclared all the vars again in func _input(event): and func _physics(delta). Also .clamped doesnt work, so use .limit_length instead. just incase anyone else gets stuck where i did, other than that all this should work in godot 4

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

      Damn.. thanks mate ❤️

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

      Limit_lenght doesnt work

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

      I'm using Godot 4

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

      @@ammonggames2421 this video works for Godot 3... Godot 4 changed a lot... So it won't work

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

    Your videos are really useful. Thanks!❤

  • @OliverJ440
    @OliverJ440 10 หลายเดือนก่อน +3

    for all my guys using Godot 3.5.3 like me here's a short modification for the joystick script:
    extends Area2D
    onready var bigCircle = $BigCircle
    onready var smallCircle = $BigCircle/SmallCircle
    onready var max_distance = $CollisionShape2D.shape.radius
    var touched = false
    func _input(event):
    if event is InputEventScreenTouch:
    var distance = event.position.distance_to(bigCircle.global_position)

    if not touched:
    if distance < max_distance:
    touched = true
    else:
    # Reset smallCircle's position if it's out of range
    smallCircle.global_position = bigCircle.global_position + max_distance * (event.position - bigCircle.global_position).normalized()
    touched = true


    func _process(delta):
    if touched:
    smallCircle.global_position = get_global_mouse_position()
    # Clamp small circle
    var dist = smallCircle.global_position - bigCircle.global_position
    if dist.length() > max_distance:
    smallCircle.global_position = bigCircle.global_position + dist.normalized() * max_distance
    func get_velo():
    var joy_velo = Vector2(0,0)
    joy_velo.x = smallCircle.position.x / max_distance
    joy_velo.y = smallCircle.position.y / max_distance

    return joy_velo
    great tutorial buddy thx for the big help

    • @MokarromHossain
      @MokarromHossain  8 หลายเดือนก่อน

      You too buddy... Thanks for sharing this 😊😊

    • @kamal44714
      @kamal44714 3 หลายเดือนก่อน

      Thanks buddy for sharing this
      it helps me to save a lot of time
      big thanks to you

  • @PHDtt
    @PHDtt 10 หลายเดือนก่อน +2

    is it possible to make a tutorial for a "3D scene viewer" using godot 4 for touch screen devices with options like rotate, zoom and pan with gestures ? (similar to sketchfab 3d viewer)

    • @MokarromHossain
      @MokarromHossain  9 หลายเดือนก่อน

      Yes. It's possible but you need to figure out how to control cameras.

  • @tile-maker4962
    @tile-maker4962 หลายเดือนก่อน

    now how do you tether it to W,A,S,D keys? like if you already have keys present but up register on the joystick is W?

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

    When I touched the joystick, the small circle vanishes and also if I begin touching the joystick it will always be touched even if its not touching, so the small circle will not reset

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

      There is a problem with the touch event. So it would be a better idea to use a plugin. (+ some of the coding syntax changed in Godot 4)

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

      have you find the resolution??

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

      @@keep_watching057 nope...I kinda gave up

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

      @@MokarromHossain understand...I have found another way

    • @MokarromHossain
      @MokarromHossain  11 หลายเดือนก่อน +1

      @@keep_watching057 glad you did tht

  • @user-el5mw1hk5c
    @user-el5mw1hk5c ปีที่แล้ว +1

    I have problem in line {distance < max_distance } the debug say vector2 in float operator "

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

      that means you messed up somewhere when assigning max_distance or distance....check the distance and max_distance.....
      [btw this joystick is not the optimal solution so if you are serious about your project .... then i would recommend this :
      Godot 3: How to make a Joystick - th-cam.com/video/uGyEP2LUFPg/w-d-xo.html
      cause there are some weird bug in the way i showed..... so yeah.... ❤ ]

    • @user-el5mw1hk5c
      @user-el5mw1hk5c ปีที่แล้ว

      @@MokarromHossain thanks for reply btw

    • @user-el5mw1hk5c
      @user-el5mw1hk5c ปีที่แล้ว

      @@MokarromHossain thanks for reply btw

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

      @@user-el5mw1hk5c no problem...

  • @md.mizanurrahmanxendpdc.369
    @md.mizanurrahmanxendpdc.369 2 หลายเดือนก่อน

    Can you make a video where the joystick sync with player head like if it was made with lookat func.
    I tried my best to make but you can say I failed.what i did was:
    You know in look at func we give mouse global coordinates value that is surrounded around player/head. It then use it to retrieve a rotation value that smoothly sync with our cursor and player.
    So I tried doing the same but this time:
    Stored joysticks buttons global in var jgb -> in physic process; constantly subtracted it with jgb to have a scale range between zero to some what number -> Lastly added it with player head global coordinate to mimic the cursor behaviour of a mouse.
    Please help me, I am really stuck at this point.

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

    Guys, remember to store all pos and velocities in variables, pater signal them to the player. Also make the circle reset

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

      Thanks mate

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

      @@MokarromHossain great tutorial otherwise. wanna collab?

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

      @@GLAWKG0D
      I am kinda busy with my admission exams 😅
      Will come back...and till then.. I can't say anything for sure

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

      @@MokarromHossain ok bro hf

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

    Hi, please make a tutorial on how to create allies in godo

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

      sry....what do you mean by 'allies'....

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

      @@MokarromHossain pets that follow you around

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

    Bro rotation? :(

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

      hey...in the joystick script...add this:
      func get_rot():
      return rad2deg(small_circle.position.angle())
      *this will return the degrees for rotation....
      and in the player script...you can just say
      rotation_degrees = $UI/Joystick.get_rot()

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

      @@MokarromHossain ooh lol Thanks

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

    Wow awesome I actually didn't think an area2d could be used. For mine i used touchscreen button and stuff. Awesome video man

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

      Thanks for the feedback
      actually i used area2d just to use collisionshape2d
      cause i need a max_distance to limit the small circle...using touchscreen is a great idea but as far as i know it will act as a rectangular button....right?

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

      @@MokarromHossain he did it well.
      th-cam.com/video/uGyEP2LUFPg/w-d-xo.html
      By using the radius of the big circle.

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

    the button doesn/t releases though

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

      it is working for me....so there must be something wrong in your code...i assume you forgot something at 1:19

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

      @@MokarromHossain nah. it just doesnt go false for some reason . code is identical

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

      @@fol896 then it might have something to do with Godot itself...i will let you know if i find any solution...till then you can try this :
      th-cam.com/video/_VXtUTwTxP0/w-d-xo.html

  • @channelbizt
    @channelbizt 5 หลายเดือนก่อน

    Excellent tutorial, it doesn't work perfectly as yours does but it's got me off to a good start and I can take it from here and build the joystick just as I intend.

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

    Very urgent! Will this joystick work on android?

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

      it is working...but you need to make sure that user doesn't clicks anything else while using this joystick [it has something to do with the touch_event in Godot]
      if you are in a hurry then i would suggest to use plugin

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

      @@MokarromHossain Thank you for your quick response! I wish you good luck!

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

      @@ilyagurov5808 welcome 🥰 btw i am not that active nowadays [exam is coming soon] so it was kinda funny how i just checked comments at the perfect time 😇

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

    Wow! Finally I can finish it!

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

    This is awesome, could you adapt another joystick so u can rotate a weapon in the direction the joystick is pointing ?

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

      i guess that is where thing start o get a bit blurry...the touchscreen event is not meant for that...so i might need to find a better solution...if i can find one...i will definitely make a video ♥

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

      func update_tank_rotation():
      var direction = small_circle.position - big_circle.position
      print(direction)
      if direction.length_squared() > 0:
      var angle = direction.angle()
      GameManager.playertank.set_rotation(angle) # burada set_rotation fonksiyonuna açı değeri iletiliyor

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

    Help me please, I made a simple game on the phone on Godot 4 in which the character simply moves in all directions on the map using the joystick, I downloaded the joystick and their official website the name of the joystick is "Virtual joystick for godot 4" and everything was fine, but then I decided add a camera and make the camera follow the character. I added a camera to the joystick, it stopped working normally, I've been scratching my head for several hours. if necessary, I can provide a photo or video or code. please, help (2D)

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

      I guess you might need to make the camera current and instead of adding the camera to the joystick you might need to add the camera to the character

    • @okabeyukiarts9996
      @okabeyukiarts9996 5 หลายเดือนก่อน +1

      I have the same problem and I find no answer anywhere... It's so frustrating huhuhu

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

    Click on AssetLib, Search Joystick, click on first result "Virtual joystick" , Download And Install

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

    This is very helpful, my only question is how do you connect this to an animation tree?

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

      tbh i don't have any idea how to do that :)

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

      For example, when it's going right, it should be something like if velocity.x >0: play("run") or smth like that

  • @TetrixAnimations
    @TetrixAnimations 11 หลายเดือนก่อน

    when i heard thia music and accent i instinctively checked if my paypal is logged off and my wallet still in pocket xD

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

    did everything you said and it didnt work i got,
    Attempt to call function 'get_velo' in base 'null instance' on a null instance.

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

      did you actually added the joystick scene in the player script? i mean in the player script... you need to specify the "joystick"...by using $joystick ... if there is no joystick then it wont work

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

      @@MokarromHossain I have a pre made scene called joystick I forgot to implement it use it in script, $joystick

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

      is it working now? [sorry for late reply ... i was in my exam]

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

    Can i mate this script por a movement for 32 pixel. 32 pixel up, 32 pixel down, 32 pixel right and left with animates, can i work this joystick? Thanks!

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

    Yes SIIIIIIRRRRRRRRRRRRRRRRR

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

    Thank youuuu man, you are the best!!

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

    Nice video bro👍🏾

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

    Thanks, bro!

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

    I would like to know the background music name. Lmao

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

      Background Music : th-cam.com/video/_DJOuw9U8b0/w-d-xo.html 🤣

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

      @@MokarromHossain thanks🤣.

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

    Hello, tell me how to make allies in godot

    • @MokarromHossain
      @MokarromHossain  8 หลายเดือนก่อน

      There are many kind of allies...what do you want them to function like? 🤔

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

    Does it work for 3D like a 3D player model I want to attach it to my capsule player AKA my test player.

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

      You can use that for 3d purposes but this version is not optimal... I would still recommend using plugins for better support

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

      @@MokarromHossain I'm using Godot 4 mobile editor and I have a computer that has it but it's a Chromebook so I have no experience I hope there is a beginner's guide coding and doing other stuff I hope you can do that for beginners :)

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

      @@SpecialNeedsChamp999 I will try to make one 😅
      Btw , I guess using a plugin can be easier for beginners.

  •  2 ปีที่แล้ว

    Character controller movement please, walk , run, jump etc

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

      i already made a tutorial about platformer character controller... : th-cam.com/video/zI2AG1NKlhw/w-d-xo.html

  • @Hassan-rg7tz
    @Hassan-rg7tz 9 หลายเดือนก่อน

    Thaaaanks very helpful tutorial❤❤❤❤

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

    Does this work on 4.1?

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

      It might. But I guess it would be far more better if you use a plugin

  • @adventuretuna
    @adventuretuna 8 หลายเดือนก่อน

    the music 💀

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

    Thanks it will halp me allot ❤️❤️

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

    3:08 omg it's me

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

    That was easy, but can I use 2 at the same time on a touchscreen devices

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

      nope....that's a problem ... it would be better if you use a plugin for that...

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

      yah i later used a plugin for the game i was trying to make, (cant remember the name again tho)

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

      @@rocket007 lemme know if you ever remembered the name....

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

      Oh yes, It is Virtual Joystick 2.0 Tools 3.4 by MarcoFazio

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

      @@rocket007 thanks man... ❤❤

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

    Next : make a joystick from control node

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

      why not make a joystick using ms paint :)

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

      @@MokarromHossain make a joystick texture manually using GDScript... 🤣

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

      @@KelvinCipta 🤣🤣🤣

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

    2:49 the pop ups come too early lol :D

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

    thats awosome
    thank u so much

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

    func get_velo() :
    var joy_velo = vector2(0,0)
    joy_velo.x = small_circle.position.x / max_distance
    Joy_velo.y = small_circle

  • @Angel-vw4pj
    @Angel-vw4pj 2 ปีที่แล้ว

    Good Job!! Man

  • @rrackrr3062
    @rrackrr3062 11 หลายเดือนก่อน

    ❤Can this joystick control 3D players?

    • @MokarromHossain
      @MokarromHossain  11 หลายเดือนก่อน

      The joystick returns a value that you can convert to 3d space. Though this code is obsolete now....there are some plugins out there... they are more safe and intuitive

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

    thank you

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

    idk what he is saying can someone translate pls

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

      Don't bother translating it. This video won't work. Godot 4.0 changed the way this works so this won't work as before. 😅
      And also sorry for my weird accent 🙃

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

      oh no its alright

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

    Super. Helpful

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

    nice!

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

    Set speed to 0.75 😁

  • @Nice-vy2zs
    @Nice-vy2zs 2 ปีที่แล้ว

    Cool :0

  • @MaplewoodStreet
    @MaplewoodStreet 9 หลายเดือนก่อน

    I think you're thinking of analog stick, not joystick.

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

    I normally dont comment but youre very fun to listen to...

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

      hehe....who knew someone will find my voice interesting ♥♥

  • @StickyLabDev
    @StickyLabDev 11 หลายเดือนก่อน

    Toofast

    • @MokarromHossain
      @MokarromHossain  11 หลายเดือนก่อน

      Yeah.... sorry about that

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

    Очень помог

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

    cepet banget bang

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

      sry bro...but i gotta go fast ♥

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

      @@MokarromHossain oo, oke, thats not problem, im just joking :)

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

    if distance