Help Keymapping to Oculus Rift Hand Controller
I have this code below which switches between a first person and third person cameras for a player and currently it maps to the G key on the keyboard. I wish it to map to the left Oculus controller X button. I do NOT know how to do this. Help? Advise? I have looked through the Oculus and Unity pages for documentation and looked at the sample scripts in the VR samples without success and I please need help. I have donuts and coffee to offer as trade.... ; ) Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CamSwitcher : MonoBehaviour {
public Camera FpsCam;
public Camera TpsCam;
bool fpsCam = true;
void Start () {
FpsCam.enabled = FpsCam;
TpsCam.enabled = !fpsCam;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
fpsCam = !fpsCam;
FpsCam.enabled = FpsCam;
TpsCam.enabled = !fpsCam;
}
}
}
Answer by gerhardfunk · May 31, 2019 at 11:44 PM
Theoretically you should simply replace in line 20
if (Input.GetKeyDown(KeyCode.G))
by
if (OVRInput.GetDown(OVRInput.RawButton.X))
or whatever input read method or button you like. Just look it up here: https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/
I say "theoretically" because I'm quite a noob just staring to build my first rudimentary setups for an art project using oculus rift in unity and this simple input method, which SHOULD be working, does not work. The rift's controller buttons are dead even in the sample scenes of the sample framework delivered with the current verson (ver. 1.37) of the "oculus integration" asset from the asset store. That's why I'm here answering to an almost one year old question :/ @AnameNoUnelseHas the coffee is cold by now, right? anyone else having dead oculus rift buttons recently? ,theoretically you should just replace
if (Input.GetKeyDown(KeyCode.G))
by
if (OVRInput.Get(OVRInput.Button.One))
or
if (OVRInput.GetDown(OVRInput.Button.One))
whatever you need, look all the options up under the oculus documentation here: https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/
i say "theoretically" because I am quite a noob just starting my first experiments with oculus in unity and right now this simple input read method, which SHOULD be working, seems not to be working anymore.
probably because the current oculus implementaion from the asset store is outdated for unity 2019 (which is not really a prob, since you can use older versions), but probably because the oculus rift app update from couple of days ago is not compatible with the current implementaion from the asset store anymore.. that's why i'm here :/ that's why i'm replying to a question, wich is almost a year old...
anyone else having issues with dead rift controller buttons in unity?
@AnameNoUnelseHas the coffee is cold by now, right?
Answer by wave-rider · Oct 06, 2021 at 04:25 AM
@gerhardfunk if (OVRInput.GetDown(OVRInput.RawButton.X))
worked perfectly fine for me Thanks for posting your suggestion