- Home /
How to detect SWIPE on Gear VR
Hi Guys,
I have been unable to get the Galaxy VR to detect a swipe. I can successfully get it to detect a tap, but not a swipe.
I've tried this code, but I suspect it only supports a swipe on a phones screen and not the Gear VR built in touch pad.
if(Input.touches.Length > 0)
{
var t : Touch = Input.GetTouch(0);
if(t.phase == TouchPhase.Began)
{
//save began touch 2d point
firstPressPos = new Vector2(t.position.x,t.position.y);
}
if(t.phase == TouchPhase.Ended)
{
//save ended touch 2d point
secondPressPos = new Vector2(t.position.x,t.position.y);
//create vector from the two points
currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);
//normalize the 2d vector
currentSwipe.Normalize();
//swipe upwards
if(currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
{
Debug.Log("up swipe");
}
//swipe down
if(currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
{
Debug.Log("down swipe");
}
//swipe left
if(currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
{
Debug.Log("left swipe");
}
//swipe right
if(currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
{
LaunchNewAsteroid();
//Debug.Log("right swipe");
}
}
}
Has anyone successfully done this or can provide a link to how to do it ?
Cheers
Answer by Bonahona · Apr 13, 2015 at 09:36 PM
The Gear Vr touchpad is mapped up like a mouse in unity. You can use Input.GetAxis("Mouse X") and Input.GetAxis("Mouse Y") to read the motion of the finger on the touchpad. Input.GetMouseButton(0) will detect if the finger touches the touchpad or not.
With this data, it's quite simple to build your own implementation of simple gesture detection.
Answer by Jan Rabe · Mar 28, 2016 at 02:58 PM
void Start()
{
OVRTouchpad.Create();
OVRTouchpad.TouchHandler += HandleTouchHandler;
}
private void HandleTouchHandler(object sender, EventArgs e)
{
var touchArgs = (OVRTouchpad.TouchArgs) e;
if (touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap)
{
Debug.Log("Received SingleTap");
}
else
{
Debug.Log("Received " + e);
}
}
}
source: http://forum.unity3d.com/threads/samsung-gear-vr-detect-tap-swipe.298346/#post-2270467
Answer by frikisoni · Oct 18, 2019 at 08:57 AM
I used this and it completely worked for me , as touchpad in GearVR works similar as a mouse.
Vector3 FP,LP;
float DragDistance=20f;
void Update()
{
if (Input.GetMouseButtonDown(0)) //Swipe using Buttonup/ButtonDown
{
FP = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
LP = Input.mousePosition;
}
if (Mathf.Abs(LP.x - FP.x) > DragDistance || Mathf.Abs(LP.y - FP.y) > DragDistance) //Swipe happened;
{
if (Mathf.Abs(LP.x - FP.x) > Mathf.Abs(LP.y - FP.y))
{ //If the horizontal movement is greater than the vertical movement...
if ((LP.x > FP.x)) //If the movement was to the right)
{ //Right swipe
}
else
{ //Left swipe
}
}
else
{ //the vertical movement is greater than the horizontal movement
if (LP.y > FP.y) //If the movement was up
{ //Up swipe
}
else
{ //Down swipe
}
}
}
else
{
//Tap Functionality
}
}
Your answer