Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Controller Swipe Direction

Discussion in 'Xiaomi' started by moldywarpe, Dec 2, 2018.

  1. moldywarpe

    moldywarpe

    Joined:
    Jan 18, 2017
    Posts:
    31
    Ok, on to the next issue....
    Does anybody know how to determine the swipe direction of the controller?

    Oculus provides values to interrogate
    e.g
    Swipe down = OVRInput.GetUp(OVRInput.RawButton.DpadDown)
    Swipe left = OVRInput.GetUp(OVRInput.RawButton.DpadLeft)

    Pico also provides values to interrogate
    e.g.
    SwipeDirection swipeDirection = Controller.UPvr_GetSwipeDirection(0);
    Swipe down = SwipeDirection.SwipeDown
    Swipe left = SwipeDirection.SwipeLeft

    But MiVR appears to simply provide a touch position on the ClickButton which means you have to determine when it is first touched (InputManager.ControllerState.TouchDown), and get the InputManager.ControllerState.TouchPosition then when the touch is released (InputManager.ControllerState.TouchUp) get the InputManager.ControllerState.TouchPosition and then try and calculate the drirection between the two points...!

    Surely I've missed something here and there is an easier way to do this?
    Using Mi VR SDK for Unity 1.8.7

    Cheers
     
  2. moldywarpe

    moldywarpe

    Joined:
    Jan 18, 2017
    Posts:
    31
    Meant to update - ended up having to determine based on the position the touch was first made (InputManager.ControllerState.TouchDown) and the position the touch was removed (InputManager.ControllerState.TouchUp) using InputManager.ControllerState.TouchPosition in an Update() method.

    I had to reset these values on Touch clicks i.e. InputManager.ControllerState.ClickButtonDown or InputManager.ControllerState.ClickButtonUp.

    Some sample code for those interested:
    Code (CSharp):
    1.            
    2.             if (InputManager.ControllerState.ClickButtonDown || InputManager.ControllerState.ClickButtonUp)
    3.             {
    4.                 // On click reset
    5.                 tchDown = Vector2.zero;
    6.                 tchUp = Vector2.zero;
    7.                 swipeUp = false;
    8.                 swipeDown = false;
    9.                 swipeLeft = false;
    10.                 swipeRight = false;
    11.             }
    12.             else if (InputManager.ControllerState.TouchDown)
    13.             {
    14.                 tchDown = InputManager.ControllerState.TouchPosition;
    15.             }
    16.             else if (InputManager.ControllerState.TouchUp)
    17.             {
    18.                 tchUp = InputManager.ControllerState.TouchPosition;
    19.                 //
    20.                 // Touch must start and end on the edges (0.2 leeway)
    21.                 //
    22.                 if (tchDown.x > 0.8 && tchUp.x < 0.2)
    23.                     swipeLeft = true;
    24.                 else if (tchUp.x > 0.8 && tchDown.x < 0.2)
    25.                     swipeRight = true;
    26.                 else if (tchDown.y > 0.8 && tchUp.y < 0.2)
    27.                     swipeDown = true;
    28.                 else if (tchUp.y > 0.8 && tchDown.y < 0.2 && !(tchDown == Vector2.zero))
    29.                     swipeUp = true;
    30.                 else
    31.                 {
    32.                     swipeUp = false;
    33.                     swipeDown = false;
    34.                     swipeLeft = false;
    35.                     swipeRight = false;
    36.                 }
    37.            }
    38.