Hi guys! I hope this video help! I have a tutorial on 2D Top Down Player Movement! Do check it out if you're making a PC game! kzitem.info/news/bejne/mJyazZ-qnnt8fHY
@rafcon9141
3 жыл бұрын
if anyone is using multitouch and also has the panel that parents the object covering half of the screen, in my case the right part, you will see that when you try it out and touch first the part of the screen that the panel doesnt cover and then holding you touch the one with the panel, you will see that the joystick moves to a position right in the middle of your fingers, because Input.mousePostion does the averege of all Inputs, so what you need is to get Input.touches which is the array of all touches and then figure out how to get the right finger.id by sorting the positions of each input inside the array, either by X or Y (depends in what part of the screen you want the joystick to be), then you will be able to tell which touch is more to the right, left, up or down, again depends of what you want, and you can set your joystick position to that touch position we just distinguished from the others, because that is the one we wanted. It might sound hard if you dont understand where the problem is. Anyway I'll share the code for you to try if you had the same issue I did. This is the solution I came up with. maybe I over thought and the problem was much easier to resolve, if that please let me know hahahaha using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class Joystick : MonoBehaviour { // Start is called before the first frame update public GameObject joystick; public GameObject joystickBG; public Vector2 joystickVec; private Vector2 joystickTouchPos; private Vector2 joystickOriginalPos; private float joystickRadius; public float radius = 4; void Start() { joystickOriginalPos = joystickBG.transform.position; joystickRadius = joystickBG.GetComponent().sizeDelta.y / radius; } public void PointerDown() { int i = Input.touches.Length;; if (i == 1) { joystick.transform.position = Input.mousePosition; joystickBG.transform.position = Input.mousePosition; joystickTouchPos = Input.mousePosition; } else { int id = SortArray(); joystick.transform.position = Input.touches[id].position; joystickBG.transform.position = Input.touches[id].position; joystickTouchPos = Input.touches[id].position; } } private int SortArray() { Touch[] inputlist = Input.touches; float[] listpositioninputX = new float[inputlist.Length]; int id = 0; for (int i = 0; i < inputlist.Length; i++) { listpositioninputX[i] = inputlist[i].position.x; } Comparison compare = new Comparison((numero1, numero2) => numero1.CompareTo(numero2)); Array.Sort(listpositioninputX, compare); for (int i = 0; i < inputlist.Length; i++) { if (listpositioninputX[0] == inputlist[i].position.x) { return id = inputlist[i].fingerId; } } return id; } public void Drag(BaseEventData baseEventData) { PointerEventData pointerEventData = baseEventData as PointerEventData; Vector2 dragPos = pointerEventData.position; joystickVec = (dragPos - joystickTouchPos).normalized; float joystickDist = Vector2.Distance(dragPos, joystickTouchPos); if (joystickDist < joystickRadius) { joystick.transform.position = joystickTouchPos + joystickVec * joystickDist; } else { joystick.transform.position = joystickTouchPos + joystickVec * joystickRadius; } } public void PointerUp() { joystickVec = Vector2.zero; joystick.transform.position = joystickOriginalPos; joystickBG.transform.position = joystickOriginalPos; } }
@allanagibson9914
Жыл бұрын
OMG THANK YOU
@ElCurios
2 жыл бұрын
After more than a year still helpful, thanks!
@magbabakal708
Жыл бұрын
Literally the only guide that worked for me. Thanks man!
@kesisgiyatsu4883
3 жыл бұрын
Such a clean tut! You are awesome!
@DAMKEON
3 жыл бұрын
감사합니다. 11시간 약 5트만에 성공했습니다 . thank you bro your video so lovely thanks
@victormr1601
3 жыл бұрын
Very well explained, clean and concise, thanks buddy
@Terra_Blade
Жыл бұрын
there was NO explanation of what tf he is doing.
@alyzabautista8223
3 жыл бұрын
NICE NICE. I'LL TRY IT TODAY FOR MY PROJECT AND IT REALLY SOLVED MY PROBLEM. THANKYOUSOMUCH😍🤗
@XtrminatR7
8 ай бұрын
This guy is goated 🐐🐐
@duck730
2 ай бұрын
You are my hero :) Thank you!
@0RedTree0
3 ай бұрын
I have a question - when I go to "play" after writing the script and hooking it up as seen in the video, the joystick keeps disappearing when I click and drag. I notice the joystick image and joystick BG image changes pos Z for some reason even though the movement joystick does not. What did I do wrong?
@astheatic
2 жыл бұрын
if you want that the player looks at the direction he is moving replace your player script with this code (dont forget to change script name) using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerScript : MonoBehaviour { public JoystickScript joystickScript; public float speed; private Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent(); } private void FixedUpdate() { if(joystickScript.joystickVec.y != 0) { rb.velocity = new Vector2(joystickScript.joystickVec.x * speed, joystickScript.joystickVec.y * speed); //character looks at the direction he is moving transform.rotation = Quaternion.LookRotation(Vector3.forward, joystickScript.joystickVec); } else { rb.velocity = Vector2.zero; } } }
@mohitguher
2 жыл бұрын
thank you!
@abdullahmuneeb4658
2 жыл бұрын
THANK U SOOOOOO MUCHHHHH!!!! I AM INDEBTED TO U, IT WORKS ABSOLUTLEY WONDERFULLY!!!
@JoseCruz-qs1pw
3 жыл бұрын
Thanks, I would like you to make a tutorial but to make it work with the new input system. Or maybe you can guide me to adapt this to the new system.
@johncarlosmontejo1162
3 жыл бұрын
Yes, I also want to see this with the new input system
@keremaslan1988
3 жыл бұрын
Hi, thank you for this great tutorial but i have a problem. My joystick doesn't scale with screen size although my canvas is set to scale with screen size. What should i do?
@donutercz
Жыл бұрын
Hey... i have problem... when i try to use the joystick its just disaapears, but i can see when im moving with it that its positions updates. Dont you know how to fix that?
@z.6377
7 ай бұрын
did u fix it?
@twikin3577
2 жыл бұрын
3:49 it says "Can't add script component ‘MovementJoystick’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match" Please help
@nathanael9522
2 жыл бұрын
I am having the same issue, also I used notepad to edit and make the script. I am not sure if that is why I am having the issue. Another reason for that issue in the line "public class MovementJoystick : MonoBehaviour". Make sure the public class is called "MovementJoystick" because it is case sensitive
@nathanael9522
2 жыл бұрын
Yoo i figured it out, it was because two words i accidentally capitalized when they shouldnt have been. That fixed it for me
@twikin3577
2 жыл бұрын
@@nathanael9522 i dont exaxtly remember it its long time ago but i think i just had different name of file in Unity and in that script, 2 hours of smashing my head to wall and 2 seconds to solve it😂
@Centicc
Жыл бұрын
How do you fix this??? Ive been redoing the same code for a while and never found a solution. Pls help
@twikin3577
Жыл бұрын
@@Centicc make sure your script in unity has the same name as the class
@YapGD
3 жыл бұрын
So hard but... Thanks broo, you safe my life LOL
@riccardodanielli4965
9 ай бұрын
Hi, nice quick and simple tutorial thanks, I have a question, do you know how I can do it so that with the movement of the player you can also rotate the player?
@qosku
2 жыл бұрын
Good Tutorial!!! funciona muy bien por si hay gente de habla hispana.
@IlijaLuzheckij
8 ай бұрын
Nice, but problem is that i can't add two of them
@mikeybeets3093
6 ай бұрын
Thank you for this tutorial- I’m having trouble when trying to add my joystick assets to the Source Image slot. It seems as though it’s not compatible. They’re png files. Does that make a difference?
@mnm__studios
3 жыл бұрын
please make a joystick tutorial for 3D games
@itsdamu
2 жыл бұрын
please please help me. The event system will not work for me i have tried over 50 tutorials with joysticks and none work. It all works fine no compiling errors but when i click play i cannot move the joystick around at all and it does not go to where i click and like i said it doesnt spin in a circles or anything. please help im at a complete loss
@alyzabautista8223
3 жыл бұрын
THANK YOU ANG GALING🎉👏
@BrickShot-LEGO-builds
2 жыл бұрын
This is for mobile games right? (Android/IOS)???
@dogusipeksac
3 жыл бұрын
dude this tutorial awesome like you :D
@comevodepetista345
3 жыл бұрын
someone could explain me why my joystick don't appears on my play mode? and that's not cuz the pos Z, the z position of all objects on my scene is zero
@hoosontech
3 жыл бұрын
Hi! I think you need to anchor your joystick UI correctly. Check on your joystick UI's Rect Transform, make sure the anchor point for your joystick UI is anchored to the bottom of the screen!
@kingclassic2231
Жыл бұрын
can you PLEASE make a video about how to add a second joystick that will do player shoot?
@orkun441
3 жыл бұрын
nice videos and channel! subscribed :)
@EIvinL
2 жыл бұрын
Can you make a video that show how to move a 2d character with buttons?
@tatarin_nbg
3 жыл бұрын
Thank you a lot, you sawed my game!
@gamebzee
7 ай бұрын
bro i got a error .says that the type or namespace called 'MovementJoystick' could not be found.what do i do now?
@unluckyyooo6598
Жыл бұрын
Does anyone know why does my JoystickBackground appears above my mousepoint instead of "around" the mousepoint? so the joystick will always be on the bottom of the background image.
@vanching4414
2 жыл бұрын
Thank u for the tutorial!
@blueempoleon6507
Жыл бұрын
Help! I'm trying to put some animation on my character but the the transition is not working. The conditions are correct, "if speed is greater than 0.01" but it just stays idle.
@_dimitrisbr
Жыл бұрын
still need help?
@thefrogsheart7670
Жыл бұрын
@@_dimitrisbr i need help with the fact that the joystick images dont show up when i click but it works as intended, the weird thing is that it shows if i release my finger but disappear when i click anywhere lmao wtf
@MinhTuấnĐỗ-c3k
11 ай бұрын
I have a question. If my character transitions to a new scene, how can I save the joystick so that it continues to work normally in the new game scene?
@snobbleDobble
Жыл бұрын
Why do no option appear (and two scripts) when i drag the movement script and player script into the character
@LitoMike
Жыл бұрын
same
@JCruzPorcel0
3 жыл бұрын
Hey, nice video! how to limit the screen so that it can only be used in the lower left square?
@hoosontech
3 жыл бұрын
You can scale your panel size smaller! In the tutorial, my "Movement Joystick" game object has a panel that covers the entire screen. So if you want the joystick to be used only at the bottom half of the screen, simply resize the panel smaller so that it only covers the bottom half of the screen!
@curiositytube5924
3 жыл бұрын
Hey Thats amazing! 60 subs and 1217 views! How'd you do it?!
@95mcqueen5
2 жыл бұрын
Awesome, thanks a lot
@jessestone117
3 жыл бұрын
Really great video
@mohitguher
2 жыл бұрын
how can i change rotation with given output from the movementjoystick.joystickVec;
@user-tt1tv4qz2o
2 жыл бұрын
im new to c# how to add animation for character where is the horizontal and vertical here
@targetblastsgaming202
2 жыл бұрын
i want to rotate my player what can i do
@lolyx-pf9nh
4 жыл бұрын
Thx so much pls make More Videos
@hakimimdnoor5634
Жыл бұрын
any idea why my joystick go to bottom left and not center of joystick bg?
@pistrantho
3 жыл бұрын
Please upload more, i want to help small dev cuz i want to be a dev too
@minhtrong4963
3 жыл бұрын
Thank u so much bro.
@Karoserigames
2 жыл бұрын
awesome tutorial
@boombastic1324
2 жыл бұрын
Hello pls someone help i have a error saying “The name joystickTouchPos does not exist” in movement joystick script
@bartoszzap2106
2 жыл бұрын
How to rotate with this joystick?
@monicardoso724
3 жыл бұрын
Thank you for your channel. How do you add animation to player script for touch screen?
@dendymaulana8909
3 жыл бұрын
have you found the solution?
@nicolaeadrian8077
3 жыл бұрын
Thank you !
@faiazbinnesar2937
3 жыл бұрын
Very helpful video! I want to move my character just left and right, Can you help me with that?
@phinion3995
3 жыл бұрын
I think the easiest way to create two buttons for left and right and assign the move script function of player to the on click of the button
@catezachamane
9 ай бұрын
tysm
@waflicek
Жыл бұрын
Hi, how can I can click on buttons with this joystick if I want to return for menu for example? thanks
@BLK_Blaze
9 ай бұрын
looking for the same answer xD
@khaelus_dev
Жыл бұрын
Thank you. Like 👍
@tejaskutal2922
Жыл бұрын
Will you make a video with animation
@abdallahmehrez4816
3 жыл бұрын
very helpful
@PavloZhdanov-u8s
2 жыл бұрын
Can somebody send script from joystick pls :/ When i touch it it just disapears
@marcustan6184
4 жыл бұрын
Solid brother
@Im-a-cool-cuber
2 жыл бұрын
once ive downloaded the sprites i dont know how to get them in unity
@Briezelta
2 жыл бұрын
anyone know why mine doesnt return to its orginal position?
@christiansotelohallarsis727
2 жыл бұрын
Thank u and godbless po
@ArravTwitch
3 жыл бұрын
Very good video.
@ralphjohncandolita6224
3 жыл бұрын
Why won't my player move?? I've done everything that's in the video. What else am i missing?? Thank you
@ThatTartToter
3 жыл бұрын
Are you sure you added the rigidbody2D and the Player script to the Player object in the Hierarchy?
@Arteka81
Жыл бұрын
How can i add the down and up walking animation
@darshanchaudhari2865
3 жыл бұрын
very nice .....
@khuongtunha2365
2 жыл бұрын
How to limit player's range of movement?
@dreamloggames978
3 жыл бұрын
man, please make it using bolt
@PoweR-wk8yw
2 жыл бұрын
Thanks
@the_sophile
2 жыл бұрын
Can you share the code?
@bluestepstudios
3 жыл бұрын
u should have gave us the code file it says im missing something but i cant find it
@ImGheorghe
3 жыл бұрын
thanks
@amirmohammadyazdani6929
2 жыл бұрын
Dude, Thanks for video, BUT where is the source code !?
@cryptonewsen1
3 жыл бұрын
Cool👍
@oncenabong2758
3 жыл бұрын
line 20 in player script error CS1061: 'MovementJoystick' does not contain a definition for 'y' and no accessible extension method 'y' accepting a first argument of type 'MovementJoystick' could be found (are you missing a using directive or an assembly reference?)
@mnm__studios
3 жыл бұрын
make the same tutorial for 3D game pls
@nexoknechthd619
3 жыл бұрын
How can I animate the character?
@devsack
3 жыл бұрын
I have an 32-bit computer with 8GB RAM I'm behind in all of the projects and your knowledge , I just given up today 😔 Can anyone let me suggest what to do if I have an 32-bit computer with 32-bit Unity🥺
@chermainehoo214
4 жыл бұрын
MORE VIDS PLS
@rink369
3 жыл бұрын
hi
@gamer69nub31
Жыл бұрын
not working!😡😡😡😡😡
@vipeyboii
10 ай бұрын
If you still want help, I can try to assist you
@BLK_Blaze
9 ай бұрын
@@vipeyboiidid you find a way for click UI buttons with this joystick system?
@vipeyboii
9 ай бұрын
@@BLK_Blaze no I ended up using Unity's new input system to make a mobile joystick much easier
Пікірлер: 115