Touch Movement Joystick Using the New Input System | Unity Tutorial

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 103

  • @matanyamin1
    @matanyamin1 Год назад +3

    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!

  • @ChubachubaDH
    @ChubachubaDH Год назад +1

    For some reason, there doesn't seem to be a definition for RectTransform in the floating joystick script

  • @biki_02
    @biki_02 2 года назад +1

    Bro.you are amazing.Very well explained.thank you.

  • @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.

  • @SAAVYentertainment
    @SAAVYentertainment 5 месяцев назад

    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

  • @emmanuelavanzi3998
    @emmanuelavanzi3998 Месяц назад

    I am trying to use unity 6 to develop webgl apps on mobile devices , do you think this approach is also good for mobile browsers on webGL apps or does it only work for mobile apps ?

  • @bigofbig4884
    @bigofbig4884 Год назад +1

    Thanks for tutorial, that was really Meat On Bone♥ .
    Hope You The Best.

  • @justfine9809
    @justfine9809 7 месяцев назад

    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  7 месяцев назад

      You have to create those methods in the PlayerTouchMovement.cs class. You can see them at 07:11

  • @ShironatsuKun
    @ShironatsuKun Год назад +1

    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 8 месяцев назад

      Hey did you figure out how to do this? Struggling to get it to work with "Scale with Screen Size"

  • @cgutierr-zgz
    @cgutierr-zgz 11 месяцев назад

    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  10 месяцев назад

      Yes, you can use something like EventSystem.current.IsOverGameObject or check the selected game object to see if it’s a button or slider

  • @raifazhar9727
    @raifazhar9727 6 месяцев назад

    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  5 месяцев назад

      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 5 месяцев назад

      @@LlamAcademy but how to see if the user touch at the joystick because now we are not comparing with screenwidth/2f

  • @PetersExcapades
    @PetersExcapades 9 месяцев назад

    this is amazing thank you! but im having some trouble, how can i detect if the touch is in a UI element?

    • @LlamAcademy
      @LlamAcademy  9 месяцев назад

      You can use the UI Raycast to find the specific elements docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html

  • @1onGoogle
    @1onGoogle 6 месяцев назад

    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?

  • @Tocha_official
    @Tocha_official 2 месяца назад +1

    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  Месяц назад

      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!

  • @wahebplays
    @wahebplays Год назад

    what about touchzone for camera Look (cinemachine &new input system)

  • @runrajrun
    @runrajrun 2 года назад +1

    Thanks dude! This helped a ton! :D

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Awesome 😎! Happy to hear

  • @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

  • @monkeymonkey69696
    @monkeymonkey69696 7 месяцев назад

    "Hey chris here from mom academy " youtube Subtitle (Nice Video btw ;))

    • @LlamAcademy
      @LlamAcademy  7 месяцев назад +1

      🤣 here to help you make your motherhood dream become a reality

  • @stefanpavlovic3548
    @stefanpavlovic3548 2 года назад

    03:50 But what if i really need to use "Scale With Screen Size" is there any workaround?

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      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 8 месяцев назад

      @stefanpavlovic3538 Hey did you figure out how to do this? I'm struggling to find any information on it atm.

    • @stefanpavlovic3548
      @stefanpavlovic3548 8 месяцев назад

      @@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 8 месяцев назад

      @@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.

  • @benseekings2552
    @benseekings2552 2 года назад +1

    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

  • @lucasradioativo
    @lucasradioativo Год назад

    how to add other buttons?

  • @ReaperMZM
    @ReaperMZM 4 месяца назад

    Hey man can u give me some tips for how to make it for a fixed joystick

    • @LlamAcademy
      @LlamAcademy  4 месяца назад

      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 2 месяца назад

      Sorry for the late reply thanks man

  • @alonsojetski
    @alonsojetski Год назад

    The navmesh agent component does not appear when I click add new component :(

    • @LlamAcademy
      @LlamAcademy  Год назад +1

      You may need to add the Navigation package from the package manager on very new versions of Unity

  • @TheMaykson
    @TheMaykson Год назад +1

    Thank you for this!

  • @hasanrakib4811
    @hasanrakib4811 2 года назад

    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  2 года назад +1

      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!

  • @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.

  • @programmer2AG
    @programmer2AG 2 месяца назад

    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

  • @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

  • @Stinger-rq4gy
    @Stinger-rq4gy 2 года назад

    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  Год назад +1

      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  Год назад +1

      @@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.

  • @duck730
    @duck730 5 месяцев назад

    When I select source image I have no option for circle-border-06
    Anyone know how I can get it?

    • @LlamAcademy
      @LlamAcademy  5 месяцев назад

      It's included in this video's project files on github

  • @Stinger-rq4gy
    @Stinger-rq4gy 2 года назад +1

    Thank you so much

  • @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

  • @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

  • @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.

  • @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?

    • @LlamAcademy
      @LlamAcademy  Год назад

      Great question. I think the easiest way to handle that would be on click of your Pause button, to disable input handling from the Joystick and to hide the Joystick. Then you don't necessarily have to worry about the co-mingling between the two.

  • @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! :)

  • @TheDurpaDurpa
    @TheDurpaDurpa Год назад +1

    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

  • @kolithehapty4883
    @kolithehapty4883 7 месяцев назад

    what if I don't want it to just be able to be touched on the left side?

    • @LlamAcademy
      @LlamAcademy  7 месяцев назад

      Then just don't check that condition 🙂

  • @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.

  • @ZeeshanKhan-ny8pm
    @ZeeshanKhan-ny8pm Год назад

    what if i dont want to use navmesh agent?

    • @LlamAcademy
      @LlamAcademy  Год назад

      You can do basically the same thing with transform.translate, character controller.move, or applying force to a rigidbody

  • @ozzie7034
    @ozzie7034 2 года назад +1

    Thank you!

  • @Ashkan-yf8eu
    @Ashkan-yf8eu Год назад

    Thank you!❤

  • @kastinante6883
    @kastinante6883 Год назад +1

    thanks , for a Beginner,actually useful,subscribe and like!🔥

  • @inkofthedragon
    @inkofthedragon 2 года назад +7

    Can you please do a quick rapid fire compliation of just "who me?" clips! 🤣 Thanks in advance!

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      😁 that might be a fun end of year video!

  • @andrewallbright
    @andrewallbright 2 года назад

    When will the new input system stop being new?

    • @LlamAcademy
      @LlamAcademy  2 года назад +3

      Maybe when a new one comes out? 😆

  • @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 😀

  • @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 года назад +1

      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

  • @aytekinmuratatasever
    @aytekinmuratatasever 11 месяцев назад

  • @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