浏览代码

first gamepad if no XBOX found

Raanan Weber 4 年之前
父节点
当前提交
86f911b251
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      src/Cameras/Inputs/freeCameraGamepadInput.ts

+ 6 - 2
src/Cameras/Inputs/freeCameraGamepadInput.ts

@@ -78,7 +78,12 @@ export class FreeCameraGamepadInput implements ICameraInput<FreeCamera> {
             }
         });
 
+        // check if there are already other controllers connected
         this.gamepad = manager.getGamepadByType(Gamepad.XBOX);
+        // if no xbox controller was found, but there are gamepad controllers, take the first one
+        if (!this.gamepad && manager.gamepads.length) {
+            this.gamepad = manager.gamepads[0];
+        }
     }
 
     /**
@@ -110,8 +115,7 @@ export class FreeCameraGamepadInput implements ICameraInput<FreeCamera> {
                 var normalizedRY = (RSValues.y / this.gamepadAngularSensibility) * this._yAxisScale;
                 RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
                 RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
-            }
-            else {
+            } else {
                 RSValues = { x: 0, y: 0 };
             }