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
⚠⚠⚠
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
Thanks for mentioning me here, much appreciated =D
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
@GorEldeen the original creator is MarcoFazio
Thank you
@goreldeen look who I found!
This is the most useful tutorial I've ever seen
glad i could ♥ help
True
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
Damn.. thanks mate ❤️
Limit_lenght doesnt work
I'm using Godot 4
@@ammonggames2421 this video works for Godot 3... Godot 4 changed a lot... So it won't work
Your videos are really useful. Thanks!❤
Wlcm 🥰
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
You too buddy... Thanks for sharing this 😊😊
Thanks buddy for sharing this
it helps me to save a lot of time
big thanks to you
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)
Yes. It's possible but you need to figure out how to control cameras.
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?
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
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)
have you find the resolution??
@@keep_watching057 nope...I kinda gave up
@@MokarromHossain understand...I have found another way
@@keep_watching057 glad you did tht
I have problem in line {distance < max_distance } the debug say vector2 in float operator "
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.... ❤ ]
@@MokarromHossain thanks for reply btw
@@MokarromHossain thanks for reply btw
@@user-el5mw1hk5c no problem...
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.
Guys, remember to store all pos and velocities in variables, pater signal them to the player. Also make the circle reset
Thanks mate
@@MokarromHossain great tutorial otherwise. wanna collab?
@@GLAWKG0D
I am kinda busy with my admission exams 😅
Will come back...and till then.. I can't say anything for sure
@@MokarromHossain ok bro hf
Hi, please make a tutorial on how to create allies in godo
sry....what do you mean by 'allies'....
@@MokarromHossain pets that follow you around
Bro rotation? :(
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()
@@MokarromHossain ooh lol Thanks
Wow awesome I actually didn't think an area2d could be used. For mine i used touchscreen button and stuff. Awesome video man
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?
@@MokarromHossain he did it well.
th-cam.com/video/uGyEP2LUFPg/w-d-xo.html
By using the radius of the big circle.
the button doesn/t releases though
it is working for me....so there must be something wrong in your code...i assume you forgot something at 1:19
@@MokarromHossain nah. it just doesnt go false for some reason . code is identical
@@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
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.
Very urgent! Will this joystick work on android?
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
@@MokarromHossain Thank you for your quick response! I wish you good luck!
@@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 😇
Wow! Finally I can finish it!
This is awesome, could you adapt another joystick so u can rotate a weapon in the direction the joystick is pointing ?
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 ♥
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
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)
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
I have the same problem and I find no answer anywhere... It's so frustrating huhuhu
Click on AssetLib, Search Joystick, click on first result "Virtual joystick" , Download And Install
lol...that's true 🤣
but some people want to learn.... -__-
This is very helpful, my only question is how do you connect this to an animation tree?
tbh i don't have any idea how to do that :)
For example, when it's going right, it should be something like if velocity.x >0: play("run") or smth like that
when i heard thia music and accent i instinctively checked if my paypal is logged off and my wallet still in pocket xD
Lol 🤣
did everything you said and it didnt work i got,
Attempt to call function 'get_velo' in base 'null instance' on a null instance.
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
@@MokarromHossain I have a pre made scene called joystick I forgot to implement it use it in script, $joystick
is it working now? [sorry for late reply ... i was in my exam]
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!
Yes SIIIIIIRRRRRRRRRRRRRRRRR
YO 🤟🥰
Thank youuuu man, you are the best!!
Nice video bro👍🏾
Thnx bro 🥰
Thanks, bro!
I would like to know the background music name. Lmao
Background Music : th-cam.com/video/_DJOuw9U8b0/w-d-xo.html 🤣
@@MokarromHossain thanks🤣.
Hello, tell me how to make allies in godot
There are many kind of allies...what do you want them to function like? 🤔
Does it work for 3D like a 3D player model I want to attach it to my capsule player AKA my test player.
You can use that for 3d purposes but this version is not optimal... I would still recommend using plugins for better support
@@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 :)
@@SpecialNeedsChamp999 I will try to make one 😅
Btw , I guess using a plugin can be easier for beginners.
Character controller movement please, walk , run, jump etc
i already made a tutorial about platformer character controller... : th-cam.com/video/zI2AG1NKlhw/w-d-xo.html
Thaaaanks very helpful tutorial❤❤❤❤
😶 it worked??
Does this work on 4.1?
It might. But I guess it would be far more better if you use a plugin
the music 💀
🥴🥴🥴
Thanks it will halp me allot ❤️❤️
🥰🥰
3:08 omg it's me
Yuhh bradaa
That was easy, but can I use 2 at the same time on a touchscreen devices
nope....that's a problem ... it would be better if you use a plugin for that...
yah i later used a plugin for the game i was trying to make, (cant remember the name again tho)
@@rocket007 lemme know if you ever remembered the name....
Oh yes, It is Virtual Joystick 2.0 Tools 3.4 by MarcoFazio
@@rocket007 thanks man... ❤❤
Next : make a joystick from control node
why not make a joystick using ms paint :)
@@MokarromHossain make a joystick texture manually using GDScript... 🤣
@@KelvinCipta 🤣🤣🤣
2:49 the pop ups come too early lol :D
fixed
thats awosome
thank u so much
wlcm ♥
func get_velo() :
var joy_velo = vector2(0,0)
joy_velo.x = small_circle.position.x / max_distance
Joy_velo.y = small_circle
Thanks bro
Good Job!! Man
Thx ♥
❤Can this joystick control 3D players?
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
thank you
idk what he is saying can someone translate pls
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 🙃
oh no its alright
Super. Helpful
🥰🥰
nice!
Set speed to 0.75 😁
hehe
Cool :0
🥰
I think you're thinking of analog stick, not joystick.
Um.....yeah actually
I normally dont comment but youre very fun to listen to...
hehe....who knew someone will find my voice interesting ♥♥
Toofast
Yeah.... sorry about that
Очень помог
Glad to help ❤
cepet banget bang
sry bro...but i gotta go fast ♥
@@MokarromHossain oo, oke, thats not problem, im just joking :)
if distance