- Home /
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.
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:
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 ?
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.
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 ?
$$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.
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;
}
}
}
}
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
Your answer
Follow this Question
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