Skip to content

Commit 3887256

Browse files
committed
Fix WebXR button and input detection.
Had to partially roll back the OpenXR Action Map work because WebXR doesn't use it. Instead, we manually detect the trigger and button input names that we so gracefully avoided. WebXR works again, but probably only on Touch/Pico and similar controllers.
1 parent 053404a commit 3887256

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

scenes/ball.gd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var controller_average_angular_velocity : Vector3:
5757
get():
5858
return Globals.average_vectors(last_n_angular_velocities)
5959

60+
var trigger_pressed : bool = false
6061
var grip_pressed : bool = false
6162

6263
@onready var snd_hit_ground : AudioStreamPlayer3D = $SndHitGround
@@ -155,15 +156,22 @@ func _physics_process(delta: float) -> void:
155156
last_n_angular_velocities.remove_at(0)
156157

157158
func _on_controller_button_pressed(button_name: String) -> void:
158-
if button_name == 'grip_click':
159+
# NOTE: The OpenXR mapping only uses 'grip_click' for both trigger and grip.
160+
# However, WebXR doesn't use that mapping, so we also must check the trigger
161+
# directly, as a fallback. !!!
162+
if button_name == 'trigger_click':
163+
trigger_pressed = true
164+
elif button_name == 'grip_click':
159165
grip_pressed = true
160166

161167
func _on_controller_button_released(button_name: String) -> void:
162-
var grip_was_pressed := grip_pressed
163-
if button_name == 'grip_click':
168+
var trigger_or_grip_was_pressed := trigger_pressed or grip_pressed
169+
if button_name == 'trigger_click':
170+
trigger_pressed = false
171+
elif button_name == 'grip_click':
164172
grip_pressed = false
165173

166-
if grip_was_pressed and not grip_pressed:
174+
if trigger_or_grip_was_pressed and not trigger_pressed and not grip_pressed:
167175
# Was gripping, now released.
168176
detached = true
169177
reattach_timer.start()

scenes/main.gd

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,26 @@ func _on_right_hand_button_released(button_name: String) -> void:
323323
_on_controller_button_released(button_name, right_hand)
324324

325325
func _on_controller_button_pressed(button_name: String, controller: Node) -> void:
326-
if button_name == 'quit':
326+
# NOTE: The first button name in each case is the "nice" OpenXR button name.
327+
# However, WebXR doesn't use that mapping, so we also check the clunky direct
328+
# controller names from the default Godot action set (which is always used
329+
# in WebXR) as a fallback. !!!
330+
if button_name == 'quit' or (button_name == 'by_button' and controller == left_hand) \
331+
or button_name == 'menu_button':
327332
# (e.g. Y or menu on Touch/Pico) = long-press to quit
328333
long_press_quit_timer.start()
329334
setup_long_press_label(controller, 'Quitting')
330-
elif button_name == 'calibrate':
335+
elif button_name == 'calibrate' or (button_name == 'by_button' and controller == right_hand):
331336
# (e.g. B on Touch/Pico) = long-press to calibrate
332337
long_press_calibrate_timer.start()
333338
setup_long_press_label(controller, 'Calibrating')
334-
elif button_name == 'skip':
339+
elif button_name == 'skip' or button_name == 'ax_button':
335340
# (e.g. A or X on Touch/Pico) = long-press to skip
336341
long_press_skip_timer.start()
337342
setup_long_press_label(controller, 'Skipping')
338343

339344
func _on_controller_button_released(button_name: String, _controller: Node) -> void:
340-
if button_name == 'quit' or button_name == 'calibrate' or button_name == 'skip':
345+
if button_name in ['quit', 'calibrate', 'skip', 'by_button', 'ax_button', 'menu_button']:
341346
# Cancel all long-presses
342347
long_press_skip_timer.stop()
343348
long_press_calibrate_timer.stop()

0 commit comments

Comments
 (0)