three-gamepad-controls 0.25.1 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ import { FirstPersonControls } from "three/addons/controls/FirstPersonControls.j
10
10
  export type GamepadFirstPersonControlsOptions = GamepadControlsOptions & {
11
11
  /**
12
12
  * Multiplier on `FirstPersonControls.movementSpeed` for translation.
13
+ * Applied after normalizing combined stick and trigger movement.
13
14
  * @default 1.0
14
15
  */
15
16
  moveSpeed: number;
@@ -49,6 +50,8 @@ export type GamepadFirstPersonControlsOptions = GamepadControlsOptions & {
49
50
  * `gamepadControls.update(delta)` before `controls.update(delta)` each frame.
50
51
  * Movement follows the native keyboard frame: yaw-based translation in XZ
51
52
  * and climbing along Y, independent of camera pitch and roll.
53
+ * Combined gamepad movement is limited to unit magnitude before speed and
54
+ * forward height gains, preserving smaller analog intentions unchanged.
52
55
  * Bindings and speeds are configurable via {@link GamepadFirstPersonControlsOptions}.
53
56
  */
54
57
  export declare class GamepadFirstPersonControls extends GamepadControls {
@@ -28,6 +28,8 @@ const LOOK_SPEED_SCALE = 36e3;
28
28
  * `gamepadControls.update(delta)` before `controls.update(delta)` each frame.
29
29
  * Movement follows the native keyboard frame: yaw-based translation in XZ
30
30
  * and climbing along Y, independent of camera pitch and roll.
31
+ * Combined gamepad movement is limited to unit magnitude before speed and
32
+ * forward height gains, preserving smaller analog intentions unchanged.
31
33
  * Bindings and speeds are configurable via {@link GamepadFirstPersonControlsOptions}.
32
34
  */
33
35
  var GamepadFirstPersonControls = class extends GamepadControls {
@@ -67,8 +69,9 @@ var GamepadFirstPersonControls = class extends GamepadControls {
67
69
  }
68
70
  /**
69
71
  * Applies translation in the native keyboard frame, using yaw before look.
70
- * Forward height gain uses the initial Y position; triggers are filtered
71
- * independently before combining their proportional Y displacement.
72
+ * Triggers are filtered independently before the combined movement intent
73
+ * is limited to unit magnitude. Speed and forward height gains follow this
74
+ * normalization; height gain uses the initial Y position before climbing.
72
75
  *
73
76
  * @param deltaTime - Seconds since the last frame.
74
77
  * @param moveSpeed - User-configured movement speed multiplier.
@@ -80,25 +83,32 @@ var GamepadFirstPersonControls = class extends GamepadControls {
80
83
  #applyMovement(deltaTime, moveSpeed, moveStick, buttonDeadzone, buttonMoveUp, buttonMoveDown) {
81
84
  const controls = this.#controls;
82
85
  const input = this.gamepadInput;
83
- const moveMult = deltaTime * controls.movementSpeed * moveSpeed;
84
86
  const move = input.stick(moveStick.xAxis, moveStick.yAxis, moveStick.pipeline);
85
- if (move.x !== 0 || move.y !== 0) {
87
+ const up = input.buttonValue(buttonMoveUp);
88
+ const down = input.buttonValue(buttonMoveDown);
89
+ let strafe = move.x;
90
+ let forward = -move.y;
91
+ let climb = (up > buttonDeadzone ? up : 0) - (down > buttonDeadzone ? down : 0);
92
+ const magnitude = Math.hypot(strafe, forward, climb);
93
+ if (magnitude > 1) {
94
+ strafe /= magnitude;
95
+ forward /= magnitude;
96
+ climb /= magnitude;
97
+ }
98
+ const moveMult = deltaTime * controls.movementSpeed * moveSpeed;
99
+ if (strafe !== 0 || forward !== 0) {
86
100
  const yaw = MathUtils.degToRad(this.#getOrientation().lon);
87
101
  const sinYaw = Math.sin(yaw);
88
102
  const cosYaw = Math.cos(yaw);
89
- const forward = -move.y;
90
103
  let forwardDistance = forward * moveMult;
91
104
  if (forward > 0 && controls.heightSpeed) {
92
105
  const heightDelta = MathUtils.clamp(controls.object.position.y, controls.heightMin, controls.heightMax) - controls.heightMin;
93
106
  forwardDistance += forward * deltaTime * heightDelta * controls.heightCoef * moveSpeed;
94
107
  }
95
- const strafeDistance = move.x * moveMult;
108
+ const strafeDistance = strafe * moveMult;
96
109
  controls.object.position.x += sinYaw * forwardDistance - cosYaw * strafeDistance;
97
110
  controls.object.position.z += cosYaw * forwardDistance + sinYaw * strafeDistance;
98
111
  }
99
- const up = input.buttonValue(buttonMoveUp);
100
- const down = input.buttonValue(buttonMoveDown);
101
- const climb = (up > buttonDeadzone ? up : 0) - (down > buttonDeadzone ? down : 0);
102
112
  if (climb !== 0) controls.object.position.y += climb * moveMult;
103
113
  }
104
114
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "three-gamepad-controls",
3
3
  "description": "Gamepad support for Three.js controls.",
4
- "version": "0.25.1",
4
+ "version": "0.25.2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
7
7
  "author": {