Navigation Menu

Skip to content

Commit

Permalink
fix: return zero vector for gamepad sticks when no gamepad is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
shroudedcode committed Apr 16, 2020
1 parent 91fa31e commit 429cc31
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/inputs/gamepad.ts
Expand Up @@ -106,11 +106,15 @@ export class Gamepad {
gpStick = stick
}

const {gamepad} = this
return {
label: gpStick.label,
query() {
return new Vector2(gamepad.axes[gpStick.xAxis], gamepad.axes[gpStick.yAxis])
query: () => {
if (!this.isConnected()) return new Vector2(0, 0)

return new Vector2(
this.gamepad.axes[gpStick.xAxis],
this.gamepad.axes[gpStick.yAxis],
)
},
}
}
Expand Down

0 comments on commit 429cc31

Please sign in to comment.