I am having a hard time coding my Window Mixed reality VR controllers using Open VR. All I want to do right now is have each button be able to print("something"). I found a guide that lists the Index numbers of all the controllers buttons. How would you code this properly? Here is my attempt at using a signal but it just sends a signal based on any button press.

extends ARVRController

func _on_ARVRController2_button_pressed(button):
	print("working")

Also Is it possible to link my VR controller buttons to the Projects settings/Input map section?

-Thanks-

Have you seen the VR starter tutorial on the Godot documentation? It shows how to map button presses to different commands/actions. Disclaimer: I authored the tutorial.

I don't remember exactly how I figured out which index went to each button, but the tutorial should show the most common. I think I had to restrict the input to what was standard across all three of the major VR headset controllers at the time (Oculus, Vive, and Windows Mixed reality).

As far as linking the VR buttons to the project settings, last I knew this was not possible, though things might have changed since I last tested.

Hopefully this helps! (Side note: Welcome to the forums!)

Thanks alot TwistedTwigleg!

I am really digging the VR starter tutorial! it is very helpful. I found i had to download Godot 3.0 to get stuff working properly. Maybe a lot of my problems are because I am using Godot 3.1 now?

The trigger seems to be function now and not the other buttons in 3.1 with this function working as a signal

func _on_ARVRController2_button_pressed(button): if button == 15: print("working")

How does Godot know what 15 is? How does it make the connection?

Thanks so much for your help.

@Dismantled said: Thanks alot TwistedTwigleg!

I am really digging the VR starter tutorial! it is very helpful. I found i had to download Godot 3.0 to get stuff working properly. Maybe a lot of my problems are because I am using Godot 3.1 now?

Great! I'm glad the tutorial is helpful :smile:

As for the issues, it might be because in the tutorial I was using Godot 3.0 and the OpenVR addon for Godot 3.0. It might work with Godot 3.1 if the OpenVR addon is also updated, but I haven't worked with VR since Godot 3.0, so I don't know for sure, sorry!

The trigger seems to be function now and not the other buttons in 3.1 with this function working as a signal

func _on_ARVRController2_button_pressed(button): if button == 15: print("working")

How does Godot know what 15 is? How does it make the connection?

You are using the button_pressed signal right?

For the other buttons to work, you'll need to check which index is passed (in your function above, the index is stored in the button variable).

For example, using the VR tutorial as a reference, the following should detect the trigger, the grip button, the menu button, and will print the index of any unknown button presses:

func _on_ARVRController2_button_pressed(button):
	if button == 1:
		print ("Menu button pressed!")
	elif button == 2:
		print ("Grip button pressed!")
	elif button == 15:
		print("Trigger pressed!")
	else:
		print ("Button with index: " + string(button) + " was pressed!")

I didn't test the code, but it should work.

As for how Godot knows which button was pressed, I assume the OpenVR addon detects a button/trigger/etc press, assigns it to an index number, and then passes that information to the ARVR controller class through the various exposed signals. I do not know for sure if that is how it works, but that is what I would guess is going on behind the scenes.

Thanks so much for your help.

No problem, I'm happy to help! :smiley:

Thanks! I was able to get the signals to print out the indexs! Awesome.

I only have 2 issues remaining on this topic:

  1. Get buttons working without using signals. In the Vr tutorial no signals were used?
  2. Access joystick/throttle functionality for some of the buttons.. Need an example on how to use the "float get_joystick_axis ( int axis ) const" method?

I got rumble to work that was fairly straight forward.

I figured how to print the values for the joysticks and the throttle! Just needed a _Input(event) function with var = to the get_joystick_axis(index number). Should be easy to add buttons!

extends ARVRController

func _input(event):
	
	var trackpad_vector = Vector2(-get_joystick_axis(1), get_joystick_axis(0))
	var joystick_vector = Vector2(-get_joystick_axis(5), get_joystick_axis(4))
	var trigger_throttle = get_joystick_axis(2)
	print(joystick_vector)
	print(trigger_throttle)

Is there a way to print the trigger_throttle so it only displays once(in real-time) not a new update every-time I press it?

@Dismantled said: Get buttons working without using signals. In the Vr tutorial no signals were used?

Unfortunately, I don't know how to get it working entirely without signals. In the Godot VR tutorial, the signals are connected in code using the connect function:

connect("button_pressed", self, "button_pressed")
connect("button_release", self, "button_released")

It might be possible to use just _input, but I haven't tested so I cannot say for sure.

I figured how to print the values for the joysticks and the throttle! ...

Great! I actually never figured out how to get the joystick throttle, but the tutorial didn't need it so I skipped it. I'll definitely keep this in mind for any future VR projects. Thanks for sharing the code!

Is there a way to print the trigger_throttle so it only displays once(in real-time) not a new update every-time I press it?

I don't know anyway right off, without using a Label node. According to this Godot QA answer, the draw_string function might help, but personally I have not used it so I cannot say for sure.

The easiest way is probably just to make a Label node and assign it to that, but that might be hard to see in VR.

Another thing you could try is exposing the variable to the editor using the export keyword in the definition of the variable (assuming it is a class variable and not a function variable) and then use the remote view in the editor to see the value. Not idea, but it could help.

I can't think of any other ways right now, but I'll keep thinking and will update here if I find something.


Edit: Looking at the code, you'll need to change it a bit to use the export keyword, assuming you want to go that route. Something like this should work:

extends ARVRController
export (float) var trigger_throttle = 0
func _input(event):
	var trackpad_vector = Vector2(-get_joystick_axis(1), get_joystick_axis(0))
	var joystick_vector = Vector2(-get_joystick_axis(5), get_joystick_axis(4))
	trigger_throttle = get_joystick_axis(2)
	print(joystick_vector)
	#print(trigger_throttle)

Then you can inspect the exported variable in the editor while the game is running by using the remote view.

All this has been extremely helpful TwistedTwigleg!

The export variable will work great for my purposes! I have a much greater understanding now of Vr controller inputs. I will try to test the Oculus Quest as well!

I will post here if any Vr input related problems come up or new ideas arise.

2 years later

Hello, I would like to ask about the input of the VR controller. How can I get the input position of the touchpad on the handle? Currently I can only know JOY_VR_PAD, but I want to know the specific up, down, left, and right.

a year later