瀏覽代碼

Invert the Y-axis on thumbsticks and trackpads in WebXR

(cherry picked from commit 7a0d4275a2369c939b5f2ee2cc3ac5088628ca68)
David Snopek 4 年之前
父節點
當前提交
bd0f5f50b2
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      modules/webxr/native/library_godot_webxr.js

+ 7 - 1
modules/webxr/native/library_godot_webxr.js

@@ -602,7 +602,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;
 	},