detect Swipe NEW Input system ( touch / mouse ) | how to detect swipe in unity with New Input system

  Рет қаралды 10,823

Game Dev Geeks

Game Dev Geeks

Күн бұрын

Пікірлер: 19
@jackoberto01
@jackoberto01 Жыл бұрын
I think It's important for consistency that swipeResistance is calculate based on length of the screen travelled rather than pixels. Resolutions users use can vary greatly and I believe the values you get back are pixel positions
@GameDevGeeks
@GameDevGeeks Жыл бұрын
thats an important point
@MichaelBrunner_nur_Michi
@MichaelBrunner_nur_Michi 5 ай бұрын
but don't do screen sizes vary more than pixel density? between phones and tablets, where a swipe with the thumb would still have a similar distance?
@jackoberto01
@jackoberto01 5 ай бұрын
@@MichaelBrunner_nur_Michi Screen sizes vary some but pixel density probably is more likely to vary by a huge margin. There's phones that have 720p resolutions and phones which are close to 4k in resolution that's about a 3 times increase in both width and height or 9 times increase in pixel density. While screen size may also double or triple that's unlikely if you're designing mainly for phones. An even more comprehensive solution may take the screen size into account if you want a real life "distance" as the parameter of when to trigger the detection.
@lyten4287
@lyten4287 7 ай бұрын
Thanks for such a great tutorial and for the link to the code.
@johnmichaeldeleon3298
@johnmichaeldeleon3298 16 күн бұрын
Hello, great video. Is it possible to return the Tap event ? For example to make the cube jump. Thank you
@paulstaring6188
@paulstaring6188 4 ай бұрын
Question, I keep getting the error "NullReferenceException: Object reference not set to an instance of an object MovementManager.Awake () (at Assets/Scripts/CubeMovement.cs:13)" . Any clue how to fix that?
@GameDevGeeks
@GameDevGeeks 4 ай бұрын
Hi. you can add "[DefaultExecutionOrder(-100)]" on the line above "public class SwipeDetection : MonoBehaviour" in the swipe detection script. and make sure the InputAction move has a value in the cube script. if you follow the video carefully it 'should' be working.
@jhgfghjfuzrtfchchghgf
@jhgfghjfuzrtfchchghgf 7 ай бұрын
I dont understand a thing of whats going on here. what are the things you reference? what names did you use where? how do your inputactions look like?
@GameDevGeeks
@GameDevGeeks 7 ай бұрын
Hey! in 6:30 I made a static variable for easier reference to the swipe detection object. you can search for Singlton Patten to learn more about this. as for the names I'm not sure which names you are confused about. and the input actions are inside the script instead of an input action map and you can see their bindings at 7:30
@maalainineelkharfi7493
@maalainineelkharfi7493 Жыл бұрын
thanks man, thats exactly what i needed
@ErenBR562
@ErenBR562 Жыл бұрын
How can I pinch gesture mobile to zoom in and zoom out on the camera? I created a zoom in/out function using the mouse scroll wheel, however, I would like to know how I can pinch using the new system input, thanks!
@GameDevGeeks
@GameDevGeeks Жыл бұрын
kzbin.info/www/bejne/oHy5hX6Beddqd80 sorry for late response I had connectivity issues
@ErenBR562
@ErenBR562 Жыл бұрын
@@GameDevGeeks WoooW Thanks! Do you have discord? I wanted to show you how my script is, thanks!
@ErenBR562
@ErenBR562 Жыл бұрын
@@GameDevGeeksThank you my friend! I will be deleting the message because it contains your private contact, I already added you, thank you very much!
@i_am_reshad
@i_am_reshad Жыл бұрын
it helped me a lot man, just curious how to block diagonal swipes
@GameDevGeeks
@GameDevGeeks Жыл бұрын
one simple way would be to put else to only detect in one axis or the other like this: private void DetectSwipe () { Vector2 delta = currentPos - initialPos; Vector2 direction = Vector2.zero; if(Mathf.Abs(delta.x) > swipeResistance) { direction.x = Mathf.Clamp(delta.x, -1, 1); } else if(Mathf.Abs(delta.y) > swipeResistance) { direction.y = Mathf.Clamp(delta.y, -1, 1); } if(direction != Vector2.zero & swipePerformed != null) swipePerformed(direction); }
@GameDevGeeks
@GameDevGeeks Жыл бұрын
or you can do pretty much the same thing but check which direction is swiped longer: private void DetectSwipe () { Vector2 delta = currentPos - initialPos; Vector2 direction = Vector2.zero; if(delta.magnitude > swipeResistance){ if(Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { direction.x = Mathf.Clamp(delta.x, -1, 1); } else if(Mathf.Abs(delta.y) > (Mathf.Abs(delta.x)) { direction.y = Mathf.Clamp(delta.y, -1, 1); } } if(direction != Vector2.zero & swipePerformed != null) swipePerformed(direction); }
@GameDevGeeks
@GameDevGeeks Жыл бұрын
or you can do pretty much the same thing but check which direction is swiped longer: private void DetectSwipe () { Vector2 delta = currentPos - initialPos; Vector2 direction = Vector2.zero; if(delta.magnitude > swipeResistance){ if(Mathf.Abs(delta.x) > Mathf.Abs(delta.y)) { direction.x = Mathf.Clamp(delta.x, -1, 1); } else if(Mathf.Abs(delta.y) > (Mathf.Abs(delta.x)) { direction.y = Mathf.Clamp(delta.y, -1, 1); } } if(direction != Vector2.zero & swipePerformed != null) swipePerformed(direction); }
Rotate Objects with New Input System (Touch and Mouse)
11:31
Game Dev Geeks
Рет қаралды 11 М.
Drag and Drop with New Input system! ( Touch and Mouse )
11:41
Game Dev Geeks
Рет қаралды 10 М.
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1 МЛН
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 79 МЛН
Unity's New Input System:  The Definitive Guide
32:07
DmanGames
Рет қаралды 28 М.
Swipe Movement - Unity3D (Endless Runner Type of Movement) Tutorial
15:10
Singletons in Unity (done right)
7:26
Game Dev Beginner
Рет қаралды 13 М.
Unity's NEW input system in 13 minutes
13:02
BiteMe Games
Рет қаралды 19 М.
Why Are Open Source Alternatives So Bad?
13:06
Eric Murphy
Рет қаралды 635 М.
How to Rebind Your Controls in Unity (With Icons!) | Input System
20:29
Sasquatch B Studios
Рет қаралды 23 М.
How to use Unity's New INPUT System EASILY
9:32
BMo
Рет қаралды 222 М.