Touch Movement Joystick Using the New Input System | Unity Tutorial

  Рет қаралды 33,862

LlamAcademy

LlamAcademy

Күн бұрын

Пікірлер: 102
@matanyamin1
@matanyamin1 Жыл бұрын
Sir, I want to thank you so much for this tutorial, personally this fixed me a lot of problems I had with my Inputs. Great tutorial, great explanation, Thanks!
@SAAVYentertainment
@SAAVYentertainment 4 ай бұрын
Thank you so much is very straight to the point (y) I'ive been looking to how to map one key (E) to a screen button, its very simple but there is no documentation or something about it Thank you
@bigofbig4884
@bigofbig4884 Жыл бұрын
Thanks for tutorial, that was really Meat On Bone♥ . Hope You The Best.
@biki_02
@biki_02 Жыл бұрын
Bro.you are amazing.Very well explained.thank you.
@LlamAcademy
@LlamAcademy Жыл бұрын
🙏 Thank you!
@benseekings2552
@benseekings2552 2 жыл бұрын
Thanks for the tutorial! I'm planning on swapping my mobile controls to the input system and this is just what I need. Would be good for a future video to integrate mobile controller support as well - perhaps with a basic menu to switch between both? Anyway keep up the good work.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Thanks! I hadn’t thought about that even though I have that implemented in my game 😅. I will add that to the list
@ChubachubaDH
@ChubachubaDH 11 ай бұрын
For some reason, there doesn't seem to be a definition for RectTransform in the floating joystick script
@TheDurpaDurpa
@TheDurpaDurpa Жыл бұрын
Thank you for this! just subscribed. This is almost exactly what i was looking for. One question though, i would like the exact same touch and move functionality but without the joystick being visible. Would it be possible to simply remove everything related to the joystick and having the player move in the same way no matter where i press on the screen? if not then maybe i could simply hide it in the inspector? i am building a hyper casual game. Now i have to binge watch all your content during the weekend 😂
@LlamAcademy
@LlamAcademy Жыл бұрын
What you’re describing might be kind of weird controls, but yes, you could just not render the joystick (don’t have to set the objects active) and you should be able to get it working
@TheMaykson
@TheMaykson Жыл бұрын
Thank you for this!
@Stinger-rq4gy
@Stinger-rq4gy Жыл бұрын
Thank you so much
@runrajrun
@runrajrun 2 жыл бұрын
Thanks dude! This helped a ton! :D
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Awesome 😎! Happy to hear
@programmer2AG
@programmer2AG Ай бұрын
everything is working fine in my case but the player speed is too much for some reason I am not sure what is going on
@1onGoogle
@1onGoogle 5 ай бұрын
Hi, I've created a Third person shooter game. The problem is that it has both input system (new & old). I'm also using fixed joystick. But when I build it for android and run it from my mobile device the joysticks collides with the touch screen and not working separately. Any solution?
@inkofthedragon
@inkofthedragon 2 жыл бұрын
Can you please do a quick rapid fire compliation of just "who me?" clips! 🤣 Thanks in advance!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
😁 that might be a fun end of year video!
@ozzie7034
@ozzie7034 Жыл бұрын
Thank you!
@LlamAcademy
@LlamAcademy Жыл бұрын
You’re welcome 🙌!
@PetersExcapades
@PetersExcapades 7 ай бұрын
this is amazing thank you! but im having some trouble, how can i detect if the touch is in a UI element?
@LlamAcademy
@LlamAcademy 7 ай бұрын
You can use the UI Raycast to find the specific elements docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html
@justfine9809
@justfine9809 5 ай бұрын
Hello, Wonderful Tutorial. I need help. These 3 lines giving me an error. ETouch.Touch.onFingerDown += Touch_onFingerDown; ETouch.Touch.onFingerUp += Touch_onFingerUp; ETouch.Touch.onFingerMove += Touch_onFingerMove; error:CS103 on the "Touch_onFingerDown/Up/Move" the name does not exist in the current context.
@LlamAcademy
@LlamAcademy 5 ай бұрын
You have to create those methods in the PlayerTouchMovement.cs class. You can see them at 07:11
@Ashkan-yf8eu
@Ashkan-yf8eu Жыл бұрын
Thank you!❤
@Tocha_official
@Tocha_official 14 күн бұрын
Thanks for the tutorial. But this doesn't work in Unity 2022. I've also cloned your Github and the sample scene doesn't work. The joystick never got triggered. It won't even show when I tap.
@LlamAcademy
@LlamAcademy 9 күн бұрын
Thanks for mentioning this! I cloned it fresh with 2022 LTS and see the same issue. It seems in 2022 simply doing EnhancedTouch.Enable() is not sufficient to enable touch simulation. There's a script you can attach to the Player Game Object called "Touch Simulation" that comes with the new input system package that properly enables the touch simulation. I've pushed an update to the repo so it should work out of the box on post-2021 versions. I ran into this problem in another project but didn't come back to update this one. Thanks again!
@cgutierr-zgz
@cgutierr-zgz 9 ай бұрын
Is there a way for "blocking" this joystick with UI elements on a canvas for example Buttons? I would expect to be a easy way of prioritizing a canvas click over another if theres a ui element already there like a button/slider... etc :D
@LlamAcademy
@LlamAcademy 9 ай бұрын
Yes, you can use something like EventSystem.current.IsOverGameObject or check the selected game object to see if it’s a button or slider
@monkeymonkey69696
@monkeymonkey69696 5 ай бұрын
"Hey chris here from mom academy " youtube Subtitle (Nice Video btw ;))
@LlamAcademy
@LlamAcademy 5 ай бұрын
🤣 here to help you make your motherhood dream become a reality
@raifazhar9727
@raifazhar9727 4 ай бұрын
Sir, I want to know know how can we fix the joystick to bottom left side of the screen. I tried to get the position of reactransform and then used RectTransformUtility.ScreenPointToLocalPointInRectangle but it did not work.
@LlamAcademy
@LlamAcademy 4 ай бұрын
If you want it to be fixed to bottom left you can just anchor it there on the Canvas and not move it around at all
@raifazhar9727
@raifazhar9727 4 ай бұрын
@@LlamAcademy but how to see if the user touch at the joystick because now we are not comparing with screenwidth/2f
@mrcyruscrap
@mrcyruscrap Жыл бұрын
Hi! Great tutorial! I was even able to figure out how to scale the joystick to fit different screen sizes. I have one question. My project is for PC and for android at the same time. I have input actions and control schemes: a joystick and a keyboard with a mouse. How do I make the interactions with the joystick bind to these input actions? Perhaps I need to somehow turn off the "keyboard with mouse" control scheme when I use this joystick?
@LlamAcademy
@LlamAcademy Жыл бұрын
I’m not totally sure 🤔 I think you are right about the enabling/disabling input action maps but back when I implemented my mobile + pc game I was using the old input system and just had different scripts that enabled / disabled themselves based on the platform
@kastinante6883
@kastinante6883 Жыл бұрын
thanks , for a Beginner,actually useful,subscribe and like!🔥
@XadegamerOfficial
@XadegamerOfficial 2 жыл бұрын
I would like to see camera for a third person mobile controller. Thanks for the helpful tutorials
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Sure! I had some future topics planned for the camera handling such as what you saw on the Llama Survival clips here!
@XadegamerOfficial
@XadegamerOfficial Жыл бұрын
@@LlamAcademy being trying to use this technique to make a camera control for third person controller but not getting a good result like Oceanhorn, COD mobile or even Apex mobile. If you can make a tutorial to cover any of this, I will really appreciate it.
@ShironatsuKun
@ShironatsuKun Жыл бұрын
Is there a way to make this work on UI Scale Mode of "Scale With Screen Size" properly so when you run the game on different types of mobile devices the Joystick UI will automatically scale for different mobile phone resolutions? Or is there a different way to do this easily? I tried setting the UI Scale Mode to "Scale With Screen Size" so the joystick will automatically scale based on the device's resolution but the joystick just pops up with a weird distance from the point of Touch and the Clamping is also different so I just want to ask. Thank you.
@LlamAcademy
@LlamAcademy Жыл бұрын
Yeah, you can have it scale with screen size but you may need to consider the Canvas's scale to scale up the maxMovementDistance relative to the designed size of the Canvas
@fortnoc321
@fortnoc321 6 ай бұрын
Hey did you figure out how to do this? Struggling to get it to work with "Scale with Screen Size"
@sumnererhard8865
@sumnererhard8865 Жыл бұрын
Excellent video! Curious if this joystick will work in a scene with UI elements built with UI toolkit? For example if you had a pause button on the top left of your screen that was using the UI toolkit, how would you handle distinguishing between a Joystick input vs pressing the pause button?
@wahebplays
@wahebplays Жыл бұрын
what about touchzone for camera Look (cinemachine &new input system)
@mecadiego113
@mecadiego113 Жыл бұрын
Amazing video and thank you for the tutorial! Any advice on how can I implement the joystick aiming (rotation) you tease at the end of the video. I'm having issues with that, because when I rotate the player's rigidbody, the movement (using the movement joystick) doesn't follow the forward direction
@LlamAcademy
@LlamAcademy Жыл бұрын
I’m using the same concept there, just applying the force based on the current velocity and the current forward of the player. The transform has localRotation and forward properties. You can use to apply force based on these values to smoothly accelerate and decelerate
@Ironlionm4n
@Ironlionm4n Жыл бұрын
At 5:25 how did you determine the joystick size? When I looked back in the video your joystick had a width and height of 200 so not sure where 300 came from here.
@LlamAcademy
@LlamAcademy Жыл бұрын
I was just making up a default value of 300x300 on the JoystickSize on PlayerTouchMovement so we have some size by default. You can adjust this in the Unity Inspector if it's too big/small for your game. I just played around with values until I found reasonable looking ones for my case.
@OliMakesGames
@OliMakesGames Жыл бұрын
Great tutorial! Just one thing - when I add a button to the area where the joystick is active, the joystick still jumps to that position - even though I just want to press the button. I even tried to add an event trigger to the button (pointer down) to disable the function, but it seems the Enhaned Touch gets called first so it still jumps to that position! Is there a way to "layer" the joystick so it does not jump to the button presses or is "below" the button?
@LlamAcademy
@LlamAcademy Жыл бұрын
First, I would consider if you really want to have very many buttons on the half of the screen with the joystick. Most of the time (in my opinion) that results in it being harder to play the game. If you really need them, you have a few options. Probably the easiest one is if you do a GraphicsRaycaster.Raycast from onFingerDown and see if you've touched one of your buttons. If you did, just disregard the event. If not, then proceed with the logic here.
@MarekNijaki
@MarekNijaki 2 жыл бұрын
Awesome tut! Could you make follow up with handling touches for camera itself. Eg like in Fallout Shelter game(base management mode), where you can pan camera, zoom in and out, smooth it movement, move based on swipe speed etc?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Sure, I had some future topics planned for the camera handling, so I'll add this as one of the options to look at in the future! Thanks for the idea
@alonsojetski
@alonsojetski Жыл бұрын
The navmesh agent component does not appear when I click add new component :(
@LlamAcademy
@LlamAcademy Жыл бұрын
You may need to add the Navigation package from the package manager on very new versions of Unity
@ReaperMZM
@ReaperMZM 2 ай бұрын
Hey man can u give me some tips for how to make it for a fixed joystick
@LlamAcademy
@LlamAcademy 2 ай бұрын
For fixed joystick you just don’t move the joystick around and only consider it a “successful placement” when the finger touches within the bounds of the joystick position.
@ReaperMZM
@ReaperMZM 17 күн бұрын
Sorry for the late reply thanks man
@abuzzakasm9767
@abuzzakasm9767 2 жыл бұрын
nice tutorial ..im using unity new input system .. for free look rotating camera we use delta mouse position but what will i do if i want to do the same thing for mobile ? if i use gamepad left stick it keeps rotating unless i put my finger off .. i could not find any delta stick for reading the change of value . .Can you cover this topic?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Sorry I don't think I understand the question. In this video I show how to use the delta position of the touch to drag the "knob" on the joystick for touch input controls. If you want to rotate a camera based on the delta position, you can use the same concept as here but apply it to rotation instead of position
@hasanrakib4811
@hasanrakib4811 Жыл бұрын
How can i add a second joystick on the right side of the screen. so i can use the left side joystick to move and the right side joystick to aim, like a twin stick shooter ?
@LlamAcademy
@LlamAcademy Жыл бұрын
The way I implemented this was to track if the initial contact point was on the left or right half of the screen ( < or >= Screen.width ). Then handle each touch like we did in this video and just apply the input to the player object!
@kolithehapty4883
@kolithehapty4883 5 ай бұрын
what if I don't want it to just be able to be touched on the left side?
@LlamAcademy
@LlamAcademy 5 ай бұрын
Then just don't check that condition 🙂
@lucasradioativo
@lucasradioativo Жыл бұрын
how to add other buttons?
@duck730
@duck730 3 ай бұрын
When I select source image I have no option for circle-border-06 Anyone know how I can get it?
@LlamAcademy
@LlamAcademy 3 ай бұрын
It's included in this video's project files on github
@arnabmondal3032
@arnabmondal3032 2 жыл бұрын
hey mate I was wondering if there was a way to connect the input from this joystick to a inputActionAsset and use the input from the inputactionasset to move the player
@LlamAcademy
@LlamAcademy 2 жыл бұрын
That might be possible. I thought that felt kind of backwards since you need to address the movement of the joystick handle anyway. I handle multiple input controls where touch option is handled like this and the keyboard / game pad is handled by those input actions
@tinyboy6458
@tinyboy6458 2 жыл бұрын
Plz do a video about brust compiler ❤️
@LlamAcademy
@LlamAcademy 2 жыл бұрын
I haven’t used it yet, but I do have a use case for it so I’ll make it once I have enough understanding to teach about it
@tinyboy6458
@tinyboy6458 2 жыл бұрын
@@LlamAcademy ok 😀
@maxg5196
@maxg5196 2 жыл бұрын
So how would you allow a finger to press multiple buttons at the same time by sliding over them? The implementation is I am trying to make a mobile joystick for movement on mobile, but there is also a run button above it, and if you slide your finger high enough while also dragging on the move joystick it will engage the running. Please help!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
For that one, I think I would try to make it by checking if the current touch position relative to the initial position delta was great enough that it would indicate the player had moved their finger into the "run" zone. If you really want it to be the same finger that has to initiate the "run" mechanic then you might consider making it a zone at 90% or something of the max radius. From what I've seen, usually for actions you use a second hand, no the same one that is moving the player, so I'd play with this to see if it works well or is just awkward to use.
@maxg5196
@maxg5196 2 жыл бұрын
@@LlamAcademy ok thanks. Yeah I was thinking something similar.
@ghost0fherobrine203
@ghost0fherobrine203 2 жыл бұрын
Well, I am doing this with a Rigidbody and on line 107: Vector3 scaledMovement = Player.speed * Time.deltaTime * new Vector3( I have an issue because speed isn't a part of Rigidbody so what should I do there?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Usually when using a Rigidbody for movement, your PlayerMovement script has a field defined as maximum speed such as [SerializeField] [Range(0,5)] private float MaxSpeed = 2.75f; You can then use this in place of Player.speed.
@ghost0fherobrine203
@ghost0fherobrine203 2 жыл бұрын
@@LlamAcademy Thank you! :)
@Stinger-rq4gy
@Stinger-rq4gy Жыл бұрын
Dear LIam Academy, Can This script be done with the Unity Starter Assets FPS Controller with the move and look touchpad? Could you make a tutorial on this for me for Unity Starter Assets FPS Controller? I have been stuck on this problem for a looooooong time.
@LlamAcademy
@LlamAcademy Жыл бұрын
Yes! You can apply the same idea here just to the CharacterController component on the player prefab from the starter assets instead. For aiming, you can use another joystick or some other input mechanism to apply rotation using the same concept here, but I think that one is a little more tricky.
@Stinger-rq4gy
@Stinger-rq4gy Жыл бұрын
@@LlamAcademy thank you very much for your help do you know of any float joystick scripts online that I could use and then after that once I've made the script to why you just drag it on to the move and look as a child in the hierarchy?
@LlamAcademy
@LlamAcademy Жыл бұрын
@@Stinger-rq4gy sorry, didn't understand your question. You can use the same concept for the floating joystick as we implemented here. It's just mapping the values to something else
@Stinger-rq4gy
@Stinger-rq4gy Жыл бұрын
@@LlamAcademy so I went to the unity standard assets website and I downloaded the unity starter assets pack which has a FPS controller. so when I download my unity game to my phone the look pad which makes you look around on the right side of the screen stays fixed in place. When you play games like Call of Duty mobile the look pad on the right is a floating joystick it doesn't stay fixed in place like it does but the unity starter assets FPS controller look pad. I just want to mke the lookpad on the right hand side of the screen a floating joystick. If you help me to do this in Unity on Discord I'll make you props for your game, and build some things for you, and share any assets I find on the asset store that are really good.
@ZeeshanKhan-ny8pm
@ZeeshanKhan-ny8pm 11 ай бұрын
what if i dont want to use navmesh agent?
@LlamAcademy
@LlamAcademy 11 ай бұрын
You can do basically the same thing with transform.translate, character controller.move, or applying force to a rigidbody
@andrewallbright
@andrewallbright 2 жыл бұрын
When will the new input system stop being new?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Maybe when a new one comes out? 😆
@stefanpavlovic3548
@stefanpavlovic3548 Жыл бұрын
03:50 But what if i really need to use "Scale With Screen Size" is there any workaround?
@LlamAcademy
@LlamAcademy Жыл бұрын
Yes. You can scale it with screen size but then you have to query the Canvas Scaler for the scale factor and do some additional math around that
@fortnoc321
@fortnoc321 6 ай бұрын
@stefanpavlovic3538 Hey did you figure out how to do this? I'm struggling to find any information on it atm.
@stefanpavlovic3548
@stefanpavlovic3548 6 ай бұрын
@@fortnoc321 I don't remember if i ever solved this.I abandoned that project shortly after that comment was written,now im working in godot
@fortnoc321
@fortnoc321 6 ай бұрын
@@stefanpavlovic3548 Np thanks for the reply! It was a simple fix for me, I had a safe area helper shifting my UI objects for me and it was screwing up the scaling math.
@aytekinmuratatasever
@aytekinmuratatasever 10 ай бұрын
@chiragsawajiyani8540
@chiragsawajiyani8540 2 жыл бұрын
Hi sir , I have a question like How to assign a unity event to a button.Onclick.addlisner() event. Like i have a button refrence in a script and instead of assign methode call in onclick event of that button i have a unity event in the same script which have that button refrence and invoke this event by using button.onclick.add listen (). Thanks
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi! Unity has documentation on how to do that with a bunch of options here: docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html
How to use TOUCH with the NEW Input System in Unity
24:11
samyam
Рет қаралды 72 М.
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 5 МЛН
Wait for the last one 🤣🤣 #shorts #minecraft
00:28
Cosmo Guy
Рет қаралды 22 МЛН
Top 5 Optimization Tips from Building a Mobile Game in Unity
15:54
TOUCH CONTROLS in Unity!
16:09
Brackeys
Рет қаралды 1,3 МЛН
3rd Person Controller - Unity's New Input System
40:30
One Wheel Studio
Рет қаралды 86 М.
How to use Unity's Input System
31:47
samyam
Рет қаралды 149 М.
How to Avoid Ghost Collisions | Unity Tutorial
10:04
LlamAcademy
Рет қаралды 3,4 М.
How to use Touch with NEW Input System - Unity Tutorial
21:55
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 5 МЛН