ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Swipe Detection + Trail Effect w/ New Input System - Unity Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • Detect swipes and it's direction with the new input system in Unity 2020. I also show how to add a trail renderer for a cool swipe effect.
    ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓
    sam-yam.itch.i...
    📥 Get the Source Code 📥
    / 45726030
    🔗 Relevant Video Links 🔗
    ᐅHow to use Touch with NEW Input System - Unity 2020 Tutorial
    • How to use Touch with ...
    ᐅGet Object from Mouse Click and Call Functions through Interface - Unity 2020 Tutorial
    • Get Object from Mouse ...
    ᐅUnity's New Input System 2020
    • Unity's NEW Input System
    🤝 Support Me 🤝
    Patreon: / samyg
    Donate: ko-fi.com/samyam
    Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help me fund my development projects while recommending great assets!
    😎 Cool Unity Assets 😎
    ᐅPeek - Editor Toolkit: assetstore.uni...
    ᐅEditor Console Pro: assetstore.uni...
    ᐅRainbow Folders 2: assetstore.uni...
    ⏱️ Timestamps ⏱️
    0:00 Intro
    0:52 Input Action
    2:34 Input Manager
    8:54 Swipe Detection
    14:37 Swipe Direction
    18:15 Trail Renderer
    22:46 Build
    23:57 Outro
    💖💖THANK YOU TO ALL MY PATRONS 💖💖
    ❯❯❯ My Links ❮❮❮
    💗 Patreon 💗
    / samyg
    💬 Discord Server 💬
    / discord
    🐦 Twitter 🐦
    / samyam_utube
    📚 Facebook 📚
    / samyam.youtube
    🎵 Music 🎵
    Fretless by Kevin MacLeod
    Link: incompetech.fi...
    License: creativecommons...
    👍 Like and Subscribe! 👍
    🖥️ Computer Setup 🖥️
    *As an Amazon Associate I earn from qualifying purchases.
    www.amazon.com...
    #unity3d #unitytutorial #unity2021

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

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

    For those who have the problem of the first start touch always return zero, the workaround is to delay the execution of StartTouchPrimary function in inputManager by 50ms for example
    private async void StartTouchPrimary(InputAction.CallbackContext ctx)
    {
    await Task.Delay(50);
    OnStartTouch?.Invoke(Utils.ScreenToWorld ...etc
    }
    (you can use coroutines or any other way for same thing)
    (you can do that just for the first time)

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

      This worked perfectly. Could you please elaborate the reason behind the bug itself? It will be helpful to know why this happens. Thanks.

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

      Very strange, seems to work, not sure why, would also appreciate an explanation if anyone has one. Btw works with a delay of Task.Delay(1), just to reduce the delay further :)

  • @asutoshvariar
    @asutoshvariar 3 ปีที่แล้ว +46

    I can see my new unfinished project already.

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

      🤣

  • @n8dev
    @n8dev 3 ปีที่แล้ว +10

    As usual, incredibly straight-forward and high quality tutorial! I'll definitely be talking about this next devlog, thank you so much for making these :)

  • @nedlangman8846
    @nedlangman8846 9 หลายเดือนก่อน +6

    Am I the only one that thinks this is a massively convoluted way of such a simple thing as reading a swipe gesture?

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

      I think the same jaajjajsj

    • @saifkhaled1914
      @saifkhaled1914 6 วันที่ผ่านมา

      So what is the easy and simple way you know ?

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

    If you are watching this, you can also check the Example files from the Package Manager.
    Input System have changes (1.5.1). There you can find a different way to do this.
    Support touch, mouse, and pen, at the same time.

  • @burnedtuner
    @burnedtuner 3 ปีที่แล้ว +7

    Awesome tutorial, thank you. I like how you include most of the code made in other tutorials, so it is possible to understand everything by watching just one video.

    • @samyam
      @samyam  3 ปีที่แล้ว

      Thank you!

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

    Wow. The quality of this video tutorial is exceptional for TH-cam :) You are great !:)

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

      Thank you so much!!

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

    There were some concepts in this video that were way over my head but you did a great job explaining everything. I'm pretty new to Unity and working through this video actually highlighted a bunch of stuff I didn't know about C#. It's also a good exercise in namespaces and how information is exchanged between scripts, which is something I often struggle with. Great job! You saved me from what would have been a long and disappointing day =]

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

      Glad it helped!!

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

    This is the only channel I watch at 0.5 speed.

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

      I've been trying to slow down in more recent videos 😅

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

    Spend three days in learning a tweenty-five minutes tutorial.Still believe I can become a game developer.

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

      You definitely can! Just keep going 😄

  • @vinimaykaul
    @vinimaykaul 3 ปีที่แล้ว +3

    The best tutorials on Unity. Thank you so much. You are the best.

    • @samyam
      @samyam  3 ปีที่แล้ว

      Thank you!

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

    hi, i have trouble with the first touch always register wrong. any clue where there problem is?

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

    Also, anyone know why on the first swipe, the startPosition is always the bottom left position of the canvas? Seems to be the case for @samyam as well here 14:30 on the first line drawn, you can see it starts from the bottom left, even though thats not where she clicks. Any ideas why?

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

    You don't need to use two delegates, since delegates work sort of like templates, the actual functionality is subscribed to the event.

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

    I feel grateful that I found out your channel today! This Input System playlist is fantastic! TY!

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

    If somebody is struggling with a bug that the very first start position is on the left bottom corner, I have found I guess the easiest solution.
    In the Input Action window, you need to create one additional action for example 'PrimaryStartPosition' with a binding Touchscreen>Primary Position>Start Position. This one works correctly even with the very first touch. It is a start position of touch, so in code in the InputManager you have to change a function StartTouchPrimary. Basically, you just need to swap playerControls.Touch.PrimaryStartPosition.ReadValue() with playerControls.Touch.PrimaryStartPosition.ReadValue().
    Hope it will be helpful for somebody 😅

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

    You have this breakeys vibes. I love the way you explain ❤ keep up the good work!

  • @astonpiche9532
    @astonpiche9532 3 ปีที่แล้ว

    Could be the dopamine from my code actually working but, Samyam, you are the most amazing human alive. Thank you !

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

      I’ll take it 😂 Congrats 🎉

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

    I was using this tutorial to help me out with my final project, struggled for hours trying to figure out why my touches were stuck in the center of the screen and my debug lines were tiny... your canvas distance needs to be the same as your near clip plane. my group members moved it and I didn't know lol

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

    It works, but when you reload the scene before you end the swipe it makes a NullReferenceException. It still works, nothing breaks, and i think the game doesn`t crash.

  • @antonplotnikov885
    @antonplotnikov885 3 ปีที่แล้ว

    Best unity ambassador in TH-cam! thank you

    • @samyam
      @samyam  3 ปีที่แล้ว

      Thanks! 😄

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

    here from the third link on bing lol, instantly subbed, hoping to learn more

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

    You are awesome, thanks for the tutorial!

  • @scls-sb6vg
    @scls-sb6vg หลายเดือนก่อน

    @samyam im trying to make it so that my character rotates when i swipe so should i use transform.Rotate or transform.rotation. and on start and end i get a null reference exception "object reference not set to an instance of an object" on swipedetection onenable and ondisable
    Plz help

  • @danixadem
    @danixadem 3 ปีที่แล้ว

    Thanks a a lot, I really appreciate your detailed tutorials about new Input System. Hope you upload more of those. Cheers...

    • @samyam
      @samyam  3 ปีที่แล้ว

      Thanks!

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

    I got error that says: NullReferenceException: Object reference not set to an instance of an object SwipeDetection.OnDisable () (at Assets/Scripts/SwipeDetection.cs:27
    My line at 27:
    inputManager.OnStartTouch += SwipeStart;
    Please Healp!

  • @brandonanderson8663
    @brandonanderson8663 3 ปีที่แล้ว

    Thanks for the video. To make it easier I used an extension method on the camera class to convert the coordinates.

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

    this broke my primary touch/tab [Touchscreen] input. how can I have both working?

  • @whoeverseesthatbehappy2722
    @whoeverseesthatbehappy2722 3 ปีที่แล้ว +3

    Thanks for the great vid, keep it up!
    Could you do a vid on how to implement a two-finger zoom/rotation gesture recognition, would much appreciate!

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

      Yes!

  • @seyedmortezakamali2597
    @seyedmortezakamali2597 3 ปีที่แล้ว

    I like you when you say fast "ALRIGHT"

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

    I love your tutorials! They are helping me a lot at my job. Also, you sound like Robin from Stranger Things and she is so nice. So are you : )

  • @killua287
    @killua287 3 ปีที่แล้ว

    Thank you I was just looking for this.

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

    Why does the first line always start at the bottom left corner of the camera?

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

      That’s a Unity Input System bug, try either upgrading the input system package or using the enhanced touch api as a workaround.

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

    Nice implementation👍

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

    Your tutorials are really helpful! 🙏

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

      Thank you!

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

    How can I make this more sensitive? It works fine but I want it to be very smooth to detect all the little swipes. Right now you kind of have to press hard to get it to work and sometimes it doesn't detect fast enough. Any Suggestion?

  • @seyedmortezakamali2597
    @seyedmortezakamali2597 3 ปีที่แล้ว

    Great Tutorial! thank you!

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

    Heres how i fixed 2 problems:
    nullreference problem: If youre not using the camera that is automatically created when you create a scene, you cant use Camera.main unless you set the camera`s tag to MainCamera
    lines that are too small/ invisible problem: Camera must be set to Orthographic in the inspector

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

      Thanks for mentioning!

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

      You sir is a life saver! Thanks for the tip about setting the camera to Orthographic!

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

    At 14:25, it almost looks like you illustrate your point using a different script (different InputManager) than the one you had been referencing/writing throughout the tutorial beforehand. This admittedly makes it pretty hard to follow, any advice if we're hitting errors here? (For me, no Debug.Drawlines are showing up in my editor when I play.)

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

      Unfortunately, I have the same issue and am not sure how to fix this.

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

      So it's been about 10 months since you asked this question. I hope you found an answer by now, but for those who may be facing a similar issue:
      The issue may well be related to the camera frustum. In the scene view click on your camera. You should see a pyramid shaped outline with the point near your camera. That's the frustum. The ScreenToWorld() method in samyams's video causes the lines and trail to be rendered at the very tip of the frustum nearest the camera. You may have to zoom in on that small portion of the screen to see the lines and trail.
      There are a few ways to change the behavior. You can move the near clipping plane away from the camera using the camera's inspector. Note that nothing closer to the camera than the near clip plane will be rendered.
      You can also change ScreenToWorld() to draw the lines at any arbitrary z-depth deeper than the near clipping plane. Note that if you do you may find the trails appear to go through or behind objects in your scene.
      I did both in my test scene, I had to add a small amount (0.1) to the near clip plane when setting the z position in ScreenToWorld() in order to avoid occasional clipping issues with the trails. And I moved the near frustum further back from the camera to make it easier to see in the scene view.
      Finally, a more advanced solution would be to use a separate camera just to render the trails.
      Good luck! And thank you samyam, great videos!

  • @ilyaskoropad6909
    @ilyaskoropad6909 3 ปีที่แล้ว

    Thanks for your videos.

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

    Could this possibly work if I build this with WebGL and try using it in a mobile browser?

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

    cool ^^

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

    It is not nice after importing a file which is not in the project in the middle of the video which lets the audience nothing to do more

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

    If you get this error " You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings."
    then use this hack
    Project Settings > Player > Active Input Handling change it to both

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

      I would actually advise against that since ideally you want your whole game to be using the new input system for consistency, so I would take the time and fix the parts in code where it’s using the old one (if possible).

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

    This only works with Orthographic camera. Does anyone know how to chage the script to work with a perspective camera in a 3D scene? I would highly appreciate any guidance.

    • @BoBbY-Pal
      @BoBbY-Pal 10 วันที่ผ่านมา

      It does work for perspective camera as well.

  • @eladonstar2721
    @eladonstar2721 3 ปีที่แล้ว

    GOOD Place to learn Essentials of Unity...Good Programmer...Love u Kid...Voice seems Kid but sweet

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

    how can i get the singleton?

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

    Hey, how can I have a tap isolated from the swipe?
    I want to detect taps and swipes but when I do a swipe it naturally captures a tap

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

      Technically a tap should only be registered when the finger is lifted up from the screen under a certain time period so that shouldn’t happen (did you add the Tap interaction to the action?)

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

    im using unity new input system .. for 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 make a video on this topic

  • @andreycenteno7586
    @andreycenteno7586 3 ปีที่แล้ว

    muchas gracias tienes una linda voz y explicas muy bien todo ☺♥

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

      gracias! :)

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

    Hello, again thank you for the video, but after implementing the Touch input, I cannot trigger my button. In this case, the pause button. Could you please advice me on what to look for so that I can fix this?

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

    I Appreciate you!

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

    I love your videos they are always helpful and informative, I would like to ask a question that I need help with, I used your tutorial for touch controls ( gears ) on the screen for movement and jump, when I add these input actions to that one, should I make them into one input map or separate them ?

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

      Whatever works best for you! Typically you'd want to use different action maps when the player has to perform different actions in different areas, for example, having an action map for the UI, having an action map for underwater controls, having one for Land controls. You can also have more than one action map enabled at a time. Here's a video on action maps for more information: th-cam.com/video/NZBAr_V7r0M/w-d-xo.html
      And thanks glad you like the videos!

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

      @@samyam Thank you so much for answering my question! I will try that out. your videos are great I've been learning from them the past few months and they are incredible!

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

      Awesome glad you like them! 😁

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

    I love your easy descriptions and explanation, buy as someone whose had his issue w/ C# (and Unity) respectively, your need to slow down girl lol.

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

      Haha I agree the video was a while ago, hopefully my newer videos are much easier to follow :)

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

    Thank you!

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

    I have an error: CS0246 PlayerControls could not be found, how can I change it ?

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

    Could you help me understand, if a put my input manager as a singleton and i have multiplayer sort of speak, how will it effect it if it was singleton ?

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

    wait ok, so how do I actually put this swipe up and down to me the input I wanted to be. for example I have set up a script for jump. how do I jump while it detected swipe up, and crouch while it swipe down? Please help

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

    Love your vids!
    Just so you know, when subscribing to the input action events, you don't need the lambda you have there - you can just subscribe the method directly (providing the signature is correct)
    This is a safer way to go since you can't unsubscribe anonymous assignments.
    Cheers!

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

      Good point! I tend to forget that, will keep in mind thanks 🙂

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

      @@samyam I love the input system - so intuitive and flexible.
      Thanks again for your vids, they're awesome!

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

    Hi... This is a great video... Can we use a small object as input controller instead of finger,mouse and game pad... What about detecting the coordinates of a physical object from touch screen...will it work?

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

    whats the benefit of doing it this way rather than, using Input.GetTouch(0) than subtracting lastTouch with startTouch I am still a newb so if someone could clear my question
    th-cam.com/video/9XgJnlfKFE4/w-d-xo.html

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

    If i understood correctly the new unity input system is suppose to make it easier to use for multiple input devices such as pc, phones, controllers. How would i go about say applying this swipe feature on say mouse input drag do i just add mouse touches in the setting? and if its controller input would i be able to just easily apply directional pads to determine if its left,right etc? without doing it the old fashion way using #regions to check specific inputs?
    Also thanks for the tutorial its not too fast or too slow yet its very informative ^^

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

      Under the same action for Primary Contact you can put a mouse click and for Primary Position you can add in a mouse position and it would work on desktop with the same code. The controller joystick however is more of a delta and not a pure position, so you'd have to keep track of the current position on the screen and move it by the delta when the joystick is moved.

    • @kylestanly6995
      @kylestanly6995 3 ปีที่แล้ว

      Thank you!

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

    how can i do that in a bound eg in a recttransform or any bound

  • @this-is-gamedev
    @this-is-gamedev 2 ปีที่แล้ว

    Your tutorials on the Input System are awesome.
    I was wondering, any reason why you don't use the Player Input component?

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

      Thanks! After a year I did change my method and now recommend the PlayerInput component as it comes with a lot of handy features/built-in functionality as I describe in this video :)
      th-cam.com/video/m5WsmlEOFiA/w-d-xo.html

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

    Please link the singleton script video !!!
    Edit: Nvm use me as the SIngleton video pause screen timestamp = > 9:15

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

      And for you copypaste Eejits! here is the GitHub link:gist.github.com/mstevenson/4325117
      I was gonna copy it here but I think that would be too lazy for even me.

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

    Great tutorial. But somehow I stuck with the implementation of the swipe input. When I implement this script I cannot use my UI elements which had OnScreenButton script is on. I managed to track swipe start position and button rect over the screen and manage to call some scripts such as pause and options, but I stuck with the buttons which are rendered over another canvases. Is there any suggestion or best practices to use swipe input and buttons together?

    • @samyam
      @samyam  3 ปีที่แล้ว

      You might have to check if there is a button in that area before starting the swipe in that case, you can probably use `EventSystem.current.IsPointerOverGameObject()` to detect it, and if there is a button then don't start the swipe. Is that what you meant?

    • @kellikzoris
      @kellikzoris 3 ปีที่แล้ว

      Yeap thats exactly what I mean. But I'm not really sure where to implement this in new input system.

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

    Is this will work in 3d game if it will it require any changes in scripts or not

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

      Yeah it’ll work!

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

    Hey,
    firstly: Awesome that you create this in-depth content for people out there!!! It's awesome to get information from somewhere!
    secondly: Sadly I find it hard to follow your video(s) as you keep throwing in references to other videos and tutorials, copy-pasting content in that cannot be followed nor understood by just following this video, and generally move at a pace and knowledge-level that is not suited for beginners. If such cross-references are made, I think it'd be great to have an actual series of consecutive tutorials to follow - if that is important.
    BIG Disclaimer here: To be fair, you do not at any point state that this WERE for beginners/intermediates!!! So feedback is from an somewhat unasked-for perspective maybe.
    I just feel this video makes a deep dive on a topic which I wish was covered at a more "beginner-friendly" level.
    to elaborate:
    I've been using the new input system for a while, made a number of gamepad and keyboard+mouse controllers with it. I would consider myself an advanced beginner in a sense. Or technically much less, watching your video, I guess?! But this video, while Ok in the beginning just starts to escalate in information-bombs and depth after a few minutes - quit frankly causing me to stop watching after importing that mysterious Singleton. Which is to bad (for me, of course), but I do not feel of having any benefit of copy pasting code en-masse without any clue what is happening anymore, nor following side-story-tutorials off topic.
    I am used to making all my controllers work with what feels much simpler and straight forward components? An InputActions, something that collects input, and then a script that can translate that input into actions. done. No singletons(?), no delegates, events, Utils-scripts, statics etc... Likely my C#-understanding is just WAY to nooby for this video?! :D
    I am happy so many people seemingly breeze through your tuts, and wish i was part of them, but maybe consider making a "beginner"/less optimized-version of this?
    PS: I really mean no offense or anything of the like. just a poor fool being way overwhelmed by your tutorial of an input manager I thought I understood comfortably well as a beginner.

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

      Thanks for your comment and tips! Yes I agree I went pretty fast through the information at the time. In my latest videos I’ve set back the pace a bit and I actually redid one of the touch videos with a different format without using the singleton! th-cam.com/video/4MOOitENQVg/w-d-xo.html
      Let me know if you have any thoughts, thanks! :)

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

      @@samyam Thank you, I will check it out :)

  • @philipatha
    @philipatha 3 ปีที่แล้ว

    2020.3.14f1 - I ended up getting miniscule distances in the 0.00 range between the two points. I found that using the raw position of "touchControls.Touch.PrimaryPosition.ReadValue();" in the events works vs. converting this using the ScreenToWorld methods. I'm not exactly sure why that's the case having followed every line you had but I may have missed something critical between this video and your New Input System Tutorial.

    • @samyam
      @samyam  3 ปีที่แล้ว

      Hm that is strange. Do you mean between the previous and current position it was as if it didn’t move (minuscule distance between them)?

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

    Seems to work for simulating touch input by mouse. But as soon as I use real touch (i have a touch display), the start position always is the last endposition. I don't know why. All I could do is skip a frame by delaying the OnStartEvent by 1 frame with a Coroutine (yield return null) before firing it. Works, but isn't very clean :/

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

      Are you using touch from the Input Action Asset? If so try using the Enhanced Touch API to see if you have the same issue, or try upgrading the input system package

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

    I'm getting an error that says:
    Pointer should have exited all objects before being removed
    UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
    I believe I followed everything correctly so I'm not sure what this error is here for. Does anyone know what's going on?

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

    Works very badly in Device Simulator in Unity... In Game mode it works perfectly, but if you switch to Device Simulator, it doesn't handle directions correctly. Don't know what it might be? Sometimes appears an error like this: Screen position out of view frustum (screen pos inf, -inf, -10.000000) (Camera rect 0 0 1125 2436)
    UnityEngine.Camera:ScreenToWorldPoint (UnityEngine.Vector3

  • @anandpatil1933
    @anandpatil1933 3 ปีที่แล้ว

    Hi, for the first swipe the start position of swipe is the left lower position of near clip . What’s wrong? Later swipes it works fine.

    • @samyam
      @samyam  3 ปีที่แล้ว

      That’s a great Unity bug that they haven’t fixed 🥲 As a workaround you can use the EnhancedTouch API to get the touches or the first touch, example usage in the later part of the video here:
      th-cam.com/video/ERAN5KBy2Gs/w-d-xo.html

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

    this is not worth it at all. ever since I implemented it i face constant unity crashes. since 2 hours I'm battling these crashes now. it always happens when I stop the game int he editor. what do I need to do for unity to stop crashing??

    • @BoBbY-Pal
      @BoBbY-Pal 10 วันที่ผ่านมา

      add yield return null inside the while loop coroutine function used for trail

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

    I tried to combined your joystick Move and swipe up (Jump) together but now when I use joystick up direction my character jump too. Is there a way that can be stopped?

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

      Your joystick should have it's own Move action, and you can make the swipe trigger only the jump action. Maybe you are accidentally combining the actions somehow?

  • @jeremyquentin42
    @jeremyquentin42 3 ปีที่แล้ว

    This technique will act weird when multitouching though, as Primary Touch can switch from a finger to another. If you start dragging around with 1 finger, add a 2nd finger, then release the 1st one, the 2nd one will become primary and this will act like a very fast swipe. Is there a simple solution to that?

    • @samyam
      @samyam  3 ปีที่แล้ว

      Couple of suggestions:
      1) Try changing to Value instead of passthrough in the input action
      2) Try binding specific fingers to input actions
      3)Only do the swipe on the started callback
      3)Hmm this may seem a bit unintuitive but you can possibly keep track in a dictionary what fingers you current have in the screen and their id, then remove from the dictionary if one of the fingers is lifted and if that finger is less the top count in the hash map then don’t perform a swipe with the remaining finger that’s now the primary (but not stored as so in the dictionary)

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

    Amazing tutorial Sam! I am learning so much from your tutorials :)
    I have some questions altough. Since we are making the swipes in the screen, why do we need to convert to world coordinates?
    I think is because of the Line Draw. But in my case I am only interested in the directions. Do I need to convert?
    I think that swipe direction in screen and world would be the same, don't they?

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

      Yeah that works! You can use either in your case if you don't need to use world coordinates :)

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

      @@samyam Ok! Thanks a lot :)

  • @322ss
    @322ss 3 ปีที่แล้ว

    Click clack! Kind of off-topic question - what keyboard/switches are you using?

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

      logitech g815 blue clicky!

  • @foxfoxes1225
    @foxfoxes1225 3 ปีที่แล้ว

    hey great video! how would i go about using this utils script with cinemachine? i know i can do m_lens.nearclipplane but how would i do ScreenTworoldPoint in this case? ty for any advice in advance

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

      You can use the same function w/ Camera.main since it will be using the main camera either way (cinemachine just tells the main camera how to move with the Cinemachine Brain component)

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

    I am still a beginner when it comes to scripting and game development and I faced a problem using your Singleton approach. It returns a null reference despite the DefaultExecutionOrder line. I made sure to follow your code step by step but I can't understand why I am getting this issue. To fix it, I simply declared a public static InputManager variable and set it on Awake.

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

      Hm hard to say without seeing your code. You can also go to the Player Settings and change the order in the Script Execution Order category:
      docs.unity3d.com/Manual/class-MonoManager.html
      You can also join our Discord if you'd like and post the issue there with more detail:
      discord.gg/mj3dSnmaZc

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

    Hi! Your Video is very helpful, but I am curious if I want to drag and drop an object with touch input. Is there anyway to let the object follow my touch?

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

      Yep! On the touch down callback you can check if there is an object underneath, which I have a video for that:
      Get Object from Mouse Click and Call Functions through Interface - Unity Tutorial
      th-cam.com/video/JID7YaHAtKA/w-d-xo.html
      Then if there is, you can start a coroutine and update the gameobject position to match the finger position (using ReadValue) (you can also lerp or smooth damp to the location if you want a nice effect), then cancel the coroutine once the finger is lifted up.

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

    The problem is I'm making a game were you have to swipe through the object from a certain angle(an opening in the object) and pass through the middle of it for it to cause an action to occur. If you draw a U shape around the object it counts as a straight line through it with a raycast, which would look weird when it does the action even though they never passed through the object. I would like to hear from someone more experienced how they would handle this problem. I'm tired right now and I will be going to sleep, but tomorrow I'm going to see if I can put a collision box on the trail and check if it passes though the object. If that is a bad idea and someone has a better idea please let me know.

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

      Ok, so having a collider on the trail and object didn't work because it can't detect the collision if you swipe too fast which is really easy. I think I'm just going to use the enhanced touch api even though there will be a hit to performance. I don't really know if it is significant enough to make a difference, but I doubt it will be a problem and I don't know a better way to solve my problem.

  • @SpoinksEntertainment
    @SpoinksEntertainment 3 ปีที่แล้ว

    Heym just curious, which link in the description covers the ScreenPointToRay, I'm working on a 3d game and while using what was done in here ran into a problem, thanks for the help tho, this vide was very useful in me getting a good portion of my project knocked out

    • @samyam
      @samyam  3 ปีที่แล้ว

      Here ya go :) Good luck!
      th-cam.com/video/JID7YaHAtKA/w-d-xo.html

    • @SpoinksEntertainment
      @SpoinksEntertainment 3 ปีที่แล้ว

      @@samyam thanks, that helps a lot, im also curious tho in if me not using the ScreenPointToRay could be causing my issue. Im working on making a Temple Run style game and the swipe controls worked fine until I started working with camera stuff, my initial thought is that the issue I'm having is being caused because the Utils is only using 2d space so when the camera turns it throws off what direction is getting registered but now I'm unsure cause I'm not 100% sure on how this code from the video you linked here could help fix that problem since its sending out a raycast to detect if its hitting something, sorry for the long question just trying to get this finished, also if there is another video you could link that could help with my issue (or if the code from this video actually does fix my issue and I'm just doing small brain) please let me know

    • @samyam
      @samyam  3 ปีที่แล้ว

      If you are using screen to world coordinates it might be causing some issues since you need to pass in the correct depth to the z value of the vector you are passing in, you can try using ScreenPointToRay and see if it helps (make sure to backup your current progress!)

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

    Touch functions suck. They interfere with OnScreen Buttons and Stick

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

    At 7:00 what's the full 3D version for camera.ScreenPointToRay()?

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

      Example Usage:
      docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html

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

    Hi, great video. Is there a way to prevent the swipe from occurring when interacting with UI elements? my swipe stops working when I'm pressing down on my on-screen mobile controls.

    • @vismanTas19
      @vismanTas19 14 วันที่ผ่านมา

      Have you ever founbd what the issue was? im facing the same problem :/

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

    Thank you for the great tutorial! How to adapt it to 3d game?

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

      You can read the swipe data to do anything you want in a 3d game, what are you trying to accomplish?

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

    Hello, @samyam.
    I loved your video a lot. Even as a beginner I understood most of the code with the way you're explaining. I'm using Unity 2021.3.20f1. And I'm getting the following errors (error CS0117, error CS1061) even after triple checking my code with your video guide. Basically, the errors suggest that Input Manager script doesn't contain a definition for Instance and also don't have definitions for 'OnStartTouch' and 'OnEndTouch'. What am I doing wrong? It would be of immense help ito solve this. I finished 5 levels of my game and decided to shift to the new input system and I'm struggling with this part. If this is fixed I have 25 new levels that I can implement and test. Thank you so much.

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

      Hi, I had a similar problem and it was a spelling error for me: in the Singleton script, i had written
      var objs = FindObjectOfType(typeof(T)) as T[];
      instead of:
      var objs = FindObjectsOfType(typeof(T)) as T[];
      It's just one "s", but made all the difference for me.
      Hope this helps.

  • @youssefkassem4895
    @youssefkassem4895 3 ปีที่แล้ว

    @samyam nice tutorial but there is a better way by getting the delta and see if its a bigger than a certain value

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

      Thanks! Yes you can do that but then you’d still need a way to track the direction of the swipe

    • @youssefkassem4895
      @youssefkassem4895 3 ปีที่แล้ว

      @@samyam Hi, the delta returns a vector 2 of an x and y you can check if delta.x >= 35 or if delta.x

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

      Ah yes, you are correct :) My bad. But in some use cases you might need the positions for example if you need the player to swipe over an area, to make sure they are swiping over the rope you’d need the position of the finger. But if the delta works for you that’s good!

  • @SureshKumar-wt1xu
    @SureshKumar-wt1xu 3 ปีที่แล้ว

    Thank would be helpful 🙂 btw
    Which snippets you use for vs code pliss tell

    • @samyam
      @samyam  3 ปีที่แล้ว

      marketplace.visualstudio.com/items?itemName=kleber-swf.unity-code-snippets

    • @killua287
      @killua287 3 ปีที่แล้ว

      @@samyam Can you do like a visual studio code unity setup with the all the packages you use and stuff?

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

      I have one here th-cam.com/video/4WWX2_tZu5Q/w-d-xo.html

  • @marlonsubuyu2012
    @marlonsubuyu2012 3 ปีที่แล้ว

    Singleton doesn't work for me :(

    • @samyam
      @samyam  3 ปีที่แล้ว

      Do you have any errors in the console?

  • @paulcrawley312
    @paulcrawley312 3 ปีที่แล้ว

    can't get the near clipping plane working correctly, seems to only appear in the top left corner and as i move right it disappears into the distance, it's like the center is off by half a screen any thoughts?

    • @samyam
      @samyam  3 ปีที่แล้ว

      Is this a 2D or 3D game? The camera near plane is just an easy way to bypass having to pass in the depth value each time to the screentoworldpoint function. Make sure your objects are on the same Z axis, if not they can disappear if you move the screen because the camera is cutting off certain parts of the view

    • @paulcrawley312
      @paulcrawley312 3 ปีที่แล้ว

      @@samyam it's a 3d game, I figured out the zoom but can't use the clipping plane how would depth be handled if you can point me in the right direction, thanks for the great vids, most excellent job

    • @samyam
      @samyam  3 ปีที่แล้ว

      This video on selecting an object might help you out :)
      th-cam.com/video/JID7YaHAtKA/w-d-xo.html

    • @paulcrawley312
      @paulcrawley312 3 ปีที่แล้ว

      @@samyam Wow! so your just not only the fastest typist on the planet but probably in my 35 years of programming the best I've ever seen, the deeper I get into your videos the more I want to pay you on a regular basis!
      Do you have a video covering mouse click hold and drag using the new system? oh wait Paul you just haven't found it yet! truly amazing!
      Thank you so much for responding to us lesser gods!

    • @samyam
      @samyam  3 ปีที่แล้ว

      Thank you!! That’s a very nice comment :)
      Also, you can use the previous video as basis for clicking and dragging an object, once you click it in the interface then you can start a drag coroutine that will make an object follow your mouse (screentoworldpoint). Is that what you meant by dragging, or did you mean the camera?

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

    what extensions for vscode do you use?

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

      I have a list here on this video here: th-cam.com/video/4WWX2_tZu5Q/w-d-xo.html
      ➡Debugger for Unity
      marketplace.visualstudio.com/items?itemName=Unity.unity-debug
      ➡Unity Tools
      marketplace.visualstudio.com/items?itemName=Tobiah.unity-tools
      ➡Unity Code Snippets
      marketplace.visualstudio.com/items?itemName=kleber-swf.unity-code-snippets
      ➡C# XML Documentation (Optional)
      marketplace.visualstudio.com/items?itemName=k--kato.docomment
      ➡GDScript Theme (Optional)
      marketplace.visualstudio.com/items?itemName=JamesSauer.gdscript-theme

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

    perfect tutorial, i thought it would be Action Type = Swipe Control Vector2 :((( but no

  • @halolalala
    @halolalala 3 ปีที่แล้ว

    I just want to make simple swipe control, why this new input system looks more complicated than the old one

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

      It’s not too complicated once you get a hang of it, it actually helps simplify code by making it event based rather than polling based. It’ll definitely help code structure in the long run!

    • @halolalala
      @halolalala 3 ปีที่แล้ว

      @@samyam its hard to understand for beginner like me. I'll be back here when i got more advance skill and have a bigger project. But for now i will stick to other more simple tutorial.

    • @samyam
      @samyam  3 ปีที่แล้ว

      I have a simpler video on the input system which is more introductory if you’d like:
      th-cam.com/video/yRI44aYLDQs/w-d-xo.html

  • @hamza-trabelsi
    @hamza-trabelsi 2 ปีที่แล้ว

    this new input system gave me headache by watching this tutorial

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

    Hey! Lovely video! This has really helped us with touch controls! One small bug we're experiencing, and we see is also in your project, is that the first swipe upon running has a start point of (0,0) [A.K.A The bottom left of the screen] but every other swipe works fine. Does anyone know where this comes from? It seems to be an issue with the ReadValue(). Any help would be appreciated

    • @samyam
      @samyam  3 ปีที่แล้ว

      I had that problem as well, I posted a bug on the forum but no one responded /:
      forum.unity.com/threads/first-position-of-touch-contact-is-0-0.1039135/

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

      @@samyam Darn, still no replies, at least it has been reported now! Did you find any good hot-fix to ignore it? I'm thinking of just ignoring any input from 0,0 as it is unlikely anyone would touch there

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

      Yeah you can ignore the first touch or do it that way, i like your way better!

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

      @@samyam In the end I fixed it like this:
      If an input of 0,0 is detected then exit the method, but start a coroutine that waits one frame before calling "OnStartTouch" again, it seems to be fixed by the next frame

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

      @@MrMartyn4700 thanks mate! fix works for me and saved me hours of debugging

  • @epicdayman6200
    @epicdayman6200 3 ปีที่แล้ว

    Здравстыуйте! Я переписывал код точь-в-точь, но мне пишет ошибку "Pointer should have exited all objects before being removed"((( Подскажите, пожалуйста, в чём может быть проблема?

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

      Try changing the Pointer Behaviour in the Event System to All Pointers as Is, or try upgrading your input system package to a newer or preview version.

    • @epicdayman6200
      @epicdayman6200 3 ปีที่แล้ว

      @@samyam Большое спасибо, помогло! И помимо этого, у меня была ошибка в синглтоне, где вместо "FindObjectsOfType()" я написал "FindObjectOfType()", без s. Вы самая лучшая, продолжайте в том же духе!)

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

      @@epicdayman6200 Thank you!! :)

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

    The new input system is so complicated…

  • @AlcadraSoykan
    @AlcadraSoykan 3 ปีที่แล้ว

    Hey I'm making a game to put in my portfolio. I want to get a job in a small mobile game company. Should I use these scripts and write your name down in comments or should I invent all of these myself?

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

      If you write the code it is yours, no need to put my name anywhere :) Anyways, this would only be a small part of your project, you still need the actual gameplay! Good luck!

    • @AlcadraSoykan
      @AlcadraSoykan 3 ปีที่แล้ว

      @@samyam :D Thank you. Good luck to you too.