Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
thorp's avatar
thorp
Honored Guest
11 years ago

Over-ridding the space bar for OVRMenu

Several alpha testers have suggested that I change the function of the space key in the forthcoming Oculus Share app "Hitchhiker". The current function of the space key is to bring up the OVRMenu. The new function would be to jump off the spaceship. However, it appears the current OVR code hardwires the space key to bring up the OVRMenu. It is common in game design for the space key to cause the player to 'jump' in one fashion or another so I suspect others will end up in my situation and I'd like to post a solution which may improve the maintainability of app developer's code over the long run.

In the forums I've found this thread:
viewtopic.php?f=37&t=6315&p=87412&hilit=menu#p87412

I prefer not to make any changes to the OVR code, a practice which allows me to upgrade to the current release quickly and easily. I'm hoping that by sharing the changes I've made, someone can show me how to do it in a more maintainable fashion or that the technique gets adopted by the OVR unityIntegration package.

Here's the approach:
1) Free the space bar from the OVR code by tying the script's invocation to a button variable labeled "Menu". (Reference: http://unity3d.com/learn/tutorials/modules/beginner/scripting/get-button-and-get-key)
2) Add a "Menu" input control to Unity3d.

Details:
1) Change code in OVRMainMenu.cs
a) Change line 846
FROM: bool SpaceHit = Input.GetKey("space");
TO: bool SpaceHit = Input.GetButton("Menu" );

2) Add a "Menu" input control to Unity:
a) In Unity go to edit> project settings> input
b) Increment the 'Size' field by one
c) Change the name of the newly created field to "Menu"
d) Change the positive input field to 'm', or whatever key you'd like to use to invoke the MainMenu.

Please take this as a constructive suggestion to address the growing number of key bindings in 0.3.2 beta. I may be totally wrong in my approach so please feel free to suggest other ways to "free the space bar" or over-ride the OVR default key bindings.

3 Replies

Replies have been turned off for this discussion
  • Thanks for the good ideas, thorp. I have made it possible to remap the menu toggle and quit actions to keys other than Space and Esc. In general, it is difficult to make all of the keys remappable. Unity's input manager does not seem to allow scripts to set the mappings. It could be cumbersome to have each client go into their project settings to set them all. Another option is to allow any keycode for any action on a per-script basis. We've taken this approach for some very-common keys. If you need a much different behavior, I would suggest making your own version of the relevant script.
  • I'd recommend just disabling that boolean, it's a quick and easy change.

    Just goto line 846 of OVRMainMenu.cs and change:

    bool SpaceHit = Input.GetKey("space");

    to
    bool SpaceHit = false;

    Hope that helps.
  • thorp's avatar
    thorp
    Honored Guest
    Thanks vrdaveb, You read my mind regarding the quit key. :-) Good point that the input data structure can't be added to programmatically. I sent in a request to Unity that the capability be added.

    Also thanks cyberreality, that is a quick way to free up the space bar. In the original post I neglected to mention that if a developer wanted to recompile for each release, the following code would remap the MainMenu function to a new key of the developer's choice:
    bool SpaceHit = Input.GetKey(KeyCode.M);

    where KeyCode.M is modified to the key that the developer would like to use.