From 7a0d4275a2369c939b5f2ee2cc3ac5088628ca68 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Fri, 8 Jan 2021 09:23:05 -0600 Subject: [PATCH] Invert the Y-axis on thumbsticks and trackpads in WebXR --- modules/webxr/native/library_godot_webxr.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/webxr/native/library_godot_webxr.js b/modules/webxr/native/library_godot_webxr.js index 447045ed279..3041c16c791 100644 --- a/modules/webxr/native/library_godot_webxr.js +++ b/modules/webxr/native/library_godot_webxr.js @@ -601,7 +601,13 @@ const GodotWebXR = { const buf = GodotRuntime.malloc((axes_count + 1) * 4); GodotRuntime.setHeapValue(buf, axes_count, 'i32'); for (let i = 0; i < axes_count; i++) { - GodotRuntime.setHeapValue(buf + 4 + (i * 4), controller.gamepad.axes[i], 'float'); + let value = controller.gamepad.axes[i]; + if (i === 1 || i === 3) { + // Invert the Y-axis on thumbsticks and trackpads, in order to + // match OpenXR and other XR platform SDKs. + value *= -1.0; + } + GodotRuntime.setHeapValue(buf + 4 + (i * 4), value, 'float'); } return buf; },