Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Apr 03, 2016 at 02:33 PM by RealJo for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RealJo · Apr 02, 2016 at 10:39 PM · android2dtouch controlsswipe

How to detect a swipe in ANY direction?

I would like to make a little 2D mobile game (Android) , when you swipe anywhere on the screen, the character should move in that direction. Not only left, right, up and down, but any direction.

I´m new to Unity and it would be awesome if someone could help me THX.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1

Answer by sunderplugs11 · Apr 03, 2016 at 04:06 AM

im not the best, but about what tou need to do is use Input.GetTouch(0).deltaposition to get your values, then setup if statements to check like (and this is probably the worst way because im new)

 if(input.gettouch(0).deltaposition.x > 0){
 debug.log("user is swiping to the right");
 }
 
 if(input.gettouch(0).deltaposition.x < 0){
 debug.log("user is swiping to the left"):
 }
 
 if(input.gettouch(0).deltaposition.y < 0){
 debug.log("user is swiping to down"):
 }
 
 if(input.gettouch(0).deltaposition.y >0){
 debug.log("user is swiping to up"):
 }
 

put all that in update.

So "Input.GetTouch" gets touches from the input manager Unity makes, then (0) signifies to use the first touch. "deltaposition" is the change in position from last frame (if i remember correctly). You just uise that data to determine how the touch is moving, which is of course a swiping motion if touch(0) has its value changed.

currently im using that for rotating a cannon up and down using

 if(shootingEnabled==true && Input.touchCount > 0  && Input.GetTouch(0).deltaPosition.y > 0 )
         {
             
             RotateDown();
         }
 
         if(shootingEnabled==true && Input.touchCount > 0  && Input.GetTouch(0).deltaPosition.y < 0 )
         {
             
             MoveUP();
         }
 


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Max_power1965 · May 10, 2017 at 12:37 PM 1
Share

Hi guys, I wrote this simple tutorial wich is basically 7 lines of code and works like a charm. Easy and simple. You just have to use te build in Unity event system ins$$anonymous$$d to write long and useless code. No need to use an update or fixed update.

avatar image jamiecorkhill5 Max_power1965 · Feb 17, 2018 at 09:03 PM 0
Share

@$$anonymous$$ax_power1965 Can I see your code?

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Easy onTouch movement 2D 0 Answers

Error : The second touch should not work at all. How do I fix this error?,Error: The second touch should not work at all. How do I fix this error? 0 Answers

Error CS1026: Unexpected symbol ;, expecting ) 0 Answers

Android 2D platformer, low fps 1 Answer

My 2D Android game(in unity) is not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges