Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by lucax · Mar 26, 2014 at 11:57 AM · androidtouchswipeinput.touch

Swipe control for circle (Can do swipe left/right)

I am using simple swipe control for left right as follows :

    //Initializing fp and lp as vector2 
     foreach (Touch touch in Input.touches) {
                 if(touch.phase == TouchPhase.Began)
                 {
                     Debug.Log ("Touch Began");
                     fp = touch.position;
                     lp = touch.position;
                 }
                 if(touch.phase == TouchPhase.Moved)
                 {
                     lp = touch.position;
                 }
                 if(touch.phase == TouchPhase.Ended)
                 {
                     if((fp.x - lp.x) > 50)
                     {
                         //Left Swipe
                         Debug.Log ("Swiped Left!");
                     }
                                     //... continuing down

Now the deal is I want a circle swipe, and if I try to use && operator in the above condition to make a condition that include up and left it will perform both up and left swipe rather than a circle. In short I am looking for a way to implement a Swipe when user makes a circle on screen. Also I've seen a few plugins so far none had circle or similar if you suggest one make sure it has in it.

Comment
Add comment · Show 5
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 pako · Mar 26, 2014 at 01:39 PM 0
Share

I don't have personal experience with this asset, but in their manual (available from their website), they specifically mention that they do circle. So, maybe you want to check it out:

https://www.assetstore.unity3d.com/#/content/1100

You can download the User manual here:

http://www.echo17.com/drawingengine.html

avatar image lucax · Mar 26, 2014 at 03:36 PM 0
Share

Oh my that looks beautiful. Thank you for suggestion!

PS : Still looking for someway to implement circle swipe in my script, any way to manipulate the fp and lp vector to make a condition for circle or semi-circle ?

avatar image robertbu · Mar 26, 2014 at 08:14 PM 0
Share

You need to explain a bit more about what you mean. If you are talking about gesture recognition, then it can be complicate. You have to capture points all along the stroke and process them. If you are talking about a single kind of stroke, you can usually hard-code something, but if you are trying to detect from multiple, different kinds of strokes, then you likely want to look to a third-party solution. In addition, there is also the radial stroke. That is, sometimes people talk about circular strokes when what they really looking for is some way intuitive way to control an object that rotates.

avatar image lucax · Mar 27, 2014 at 03:18 AM 0
Share

Okay, I just want that just like when you swipe left right(like in temple run without taking your finger off the screen) single touch but the player makes a circular swipe with finger touching the screen all the time.

This will probably use Touchphase.$$anonymous$$oved right ?

avatar image lucax · Mar 28, 2014 at 05:57 AM 0
Share

$$anonymous$$an I bet this would need some strong program$$anonymous$$g/algo heavy $$anonymous$$d to solve this problem. Again - I just want to detect everytime the player makes a simple circle on screen, just like how player makes a line(swipe) to left when he wants to say turn left in Temple Run.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Nomibuilder · Jan 24, 2015 at 01:53 PM

 using UnityEngine;
 using System.Collections;
 
 public class SwipeDetector : MonoBehaviour 
 {
     
     public float minSwipeDistY;
 
     public float minSwipeDistX;
         
     private Vector2 startPos;
 
     void Update()
     {
 //#if UNITY_ANDROID
         if (Input.touchCount > 0) 
             
         {
             
             Touch touch = Input.touches[0];
             
             
             
             switch (touch.phase) 
                 
             {
                 
             case TouchPhase.Began:
 
                 startPos = touch.position;
                 
                 break;
                 
                 
                 
             case TouchPhase.Ended:
 
                     float swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
 
                     if (swipeDistVertical > minSwipeDistY) 
                         
                     {
                         
                         float swipeValue = Mathf.Sign(touch.position.y - startPos.y);
                         
                         if (swipeValue > 0)//up swipe
 
                             //Jump ();
                         
                         else if (swipeValue < 0)//down swipe
 
                             //Shrink ();
                         
                     }
                     
                     float swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
                     
                     if (swipeDistHorizontal > minSwipeDistX) 
                         
                     {
                         
                         float swipeValue = Mathf.Sign(touch.position.x - startPos.x);
                         
                         if (swipeValue > 0)//right swipe
                             
                             //MoveRight ();
                         
                         else if (swipeValue < 0)//left swipe
                             
                             //MoveLeft ();
                         
                     }
                 break;
             }
         }
     }
 }
Comment
Add comment · 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
0

Answer by hero_kenshin · Mar 27, 2014 at 03:23 AM

Do you mean like a joystick so the player never has to take the finger off the screen?

If so check out the Penelope tutorial by unity tech Our there are scripts in the standard assets that you can look over

Comment
Add comment · Show 1 · 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 lucax · Mar 27, 2014 at 03:30 AM 0
Share

Read.. above man.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

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

Related Questions

Bug? Need to wait about 10 seconds to get back to normal 1 Answer

how to detect a mobile double tap, and a long press. PS. I already have swipe detected. 0 Answers

Button Touch for Android 2 Answers

How can I get Rect.Contains to work properly with touch input? 1 Answer

Android Drag By Steps 0 Answers


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