Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Recentering Cardboard App

Discussion in 'AR/VR (XR) Discussion' started by BamBamAlicious, Jun 4, 2017.

  1. BamBamAlicious

    BamBamAlicious

    Joined:
    Jan 29, 2017
    Posts:
    58
    Hey everyone,

    I'm playing around with the idea of building an app for Cardboard, using a controller (PS3 etc), to control a game, while wearing a headset.

    Recently it seems the Google SDK has been updated, and the GvrViewer prefab doesn't exist anymore. The problem is, I'm trying to set up recentering on a button press, to counter the drift during play.

    So far I have all these functions set up,
    Code (csharp):
    1.  
    2.         if (Input.GetKey("joystick button 8")) {
    3.             InputTracking.disablePositionalTracking = true;
    4.             InputTracking.Recenter ();
    5.             InputTracking.disablePositionalTracking = false;
    6.             GvrCardboardHelpers.Recenter ();
    7.             Debug.Log ("VR Recenter");
    8.             cam.GetComponent<GvrEditorEmulator>().Recenter ();
    9.             }
    10.  
    While in the editor, the emulator recenters exactly as intended. Button is pressed, and the camera re-sets to dead ahead. When I build however, pressing the button does absolutely nothing.

    I've been searching for three days now and none of the previous recentering systems seem to work!! I'm hoping I'm just being an idiot and this is something I've missed!!

    Fingers crossed the community has the answer!!!!
     
  2. BamBamAlicious

    BamBamAlicious

    Joined:
    Jan 29, 2017
    Posts:
    58
    So.... I feel like an Idiot!

    Turns out that while my PC and the editor are recognising a PS3 controller as a PS3 controller, on the actual device the PS3 controller is registering as an Xbox 360 controller through SixAxis. In this instance, the select button in the editor turns out to be the left stick on the device!

    Basically... moral of the story... check all the buttons (Including the sticks!). Guess I will be adding a button mapping system in the future!!

    3 days of headache solved at least!
     
  3. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,511
    Yeah there isn't a consistent number for which axis maps to what on the different platforms (standalone, android, etc.). The documentation from Unity is also not up to date and worse off different brand controllers conflict with eachother (for example using Unity input you can't generally support both xbox and playstation controllers in the same build because right stick on one will be the triggers on the other). If you need to support both rewired or incontrol are your best bet.

    If you are doing Unity input you can usually find the mappings by running my free utility instead of googling for a long time.

    https://www.assetstore.unity3d.com/en/#!/content/43621
     
  4. BamBamAlicious

    BamBamAlicious

    Joined:
    Jan 29, 2017
    Posts:
    58
    Thanks for the reply! Your tool looks incredibly useful!! I'm trying to not pay for anything while doing this, so while rewired and incontrol look good, I might go down the route of having the player map on first start, then adding ability to remap in options. Would be a good learning opportunity for me as well!