Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Building a VR simulator using a game pad as input for Unity XR

Discussion in 'AR/VR (XR) Discussion' started by Vued, Aug 2, 2020.

  1. Vued

    Vued

    Joined:
    Aug 2, 2020
    Posts:
    3
    Hi guys,

    I was wondering if a gamepad would be a better input device for simulating VR input over keyboard and mouse, so I built one. :)

    Here is the result of the prototype:


    You can find the scripts on GitHub and a guide on how to set it up in the Wiki.

    Releasing objects does not work, yet. In case you figure out how to do it, I would be happy to receive a pull request.

    I would like to share some insights with you which I got when building it.

    Manipulating the position/orientation of the camera and the game pads was pretty easy. The script controller-control-controller (sorry for this awful name) is very straight forward and easy to implement/understand.

    The tricky part was adding button presses. The reason for this can be best understood when looking at this architecture:
    https://docs.unity3d.com/Manual/XRPluginArchitecture.html
    The position of the controllers and camera are directly accessible and changeable in the XR Interaction Toolkit component (developer tools), whereas button presses are not directly accessible on this layer (only reacting on them, but not triggering them). To trigger button presses, you have to build a fake controller on the level "provider implementation". Luckily trzy had a script ready which does exactly this and shared it in thread https://forum.unity.com/threads/uni...e-input-events-via-a-fake-inputdevice.905738/. I only had to update to the new input system for simpler access to the gamepad inputs.

    I'm expecting that the Unity Interaction Toolkit team will release a VR simulator soon which is completely implemented on the bottom layer.

    Looking forward to get some feedback!
     
    Last edited: Aug 2, 2020
    tanru likes this.
  2. jvetulani

    jvetulani

    Joined:
    Dec 20, 2016
    Posts:
    43
    Hi!

    Did you test this in the latest 2020 Unity beta?

    The Base Controller object doesn't exist so you need to create one yourself, but then you get a bunch of errors on each controlller:


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. EditorControllerSimulator.LateUpdate () (at Assets/XR/Simulator/Scripts/EditorControllerSimulator.cs:73)
    EDIT:
    Nm, the errors are there when you don't have the new input system set up.
    However the main issue is that there's no canvas interaction :(.
     
    Last edited: Oct 1, 2020
unityunity