Unity-Technologies / XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit
Other
1.13k stars 365 forks source link

Teleportation Custom Triggers #42

Open PicoPlanetDev opened 4 years ago

PicoPlanetDev commented 4 years ago

Hi there! I am working on a game that uses the XR Interaction Toolkit. I have implemented walk movement using a PlayerController, but haven't yet added a teleportation option for people who are susceptible to VR sickness. The reason for this is that I would like the teleportation to occur when pressing a custom button, for example, (A) on an Index or Oculus controller. I have used CommonUsages before and know that you can get button events, but how can I translate that into a teleportation trigger? Currently, the only options are OnSelectEnter/Exit and OnActivate/Deactivate. This really doesn't make sense for a game that uses the XRRayInteractor already for distance grabbing and UI interactions. Am I missing something? Or is there a better way to do this? Any help or code snippets would be appreciated.

ericalbers commented 3 years ago

XR interaction toolkit is in preview for a reason, its really not flushed out and ready for use. Imagine it was written by a part time summer student who came into work every other day or so and hung out.

Gusinuhe commented 3 years ago

Actions (such as Hover, Select, and Activate) which are what trigger the teleportation can be mapped to specific inputs in the XR Controller component. You can use this page to help you figure out what binding corresponds to what input in your device.

hanisherif1997 commented 3 years ago

I figured out the solution. First Go to the gameobject (eg. ground) on where you have added the teleportation area. Expand the teleportation area and here you will find 'teleportation trigger'. By default it will be 'on select exited'. This means that the teleportation is triggered when the SELECT button is exited (or you release the select button). So the next obvious thing to do is to configure the SELECT button.

(Remember to install the input system package through package manager and import the XRI default presets before proceeding. Watch the video if you don't know how to do this: https://www.youtube.com/watch?v=wnn-dzHz-tA&list=PLwz27aQG0IIJ8cPM-npX2AJ6Nb-MruYP3&index=1 Watch from time stamp 3:23 to 08:26)

in the project window : search for 'xri default input actions'. Go to XRI Left Hand and here you will fiind the 'SELECT'. By default it will have gripPress. You can add the required binding here by understanding the correct 'input Feature Usage'.

For example: if you want the button Y on the left hand controller, you know that the input feature usage is 'secondaryButton' (this can be found out in the 'XR input mappings' table available here.

click the plus icon on the right side of the 'SELECT' and add binding. check Generic XR controller. In the path go to: XR controller<Xr controller left hand<Optional controls<secondaryButton.

Note: if you don’t want to mess up the select button, then create a child empty game object of the XRRig and name it teleportation. Then add the required components along with the XR base controller for teleportation to work. In this XR BASE controller, change the Select action button to custom button that is defined in the XRI default input actions. (U can add ur own new actions here and set it to the select) watch this video and go to the time stamp: 09.10 https://youtu.be/9dc1zq8eH54