three-gamepad-controls 0.25.0 → 0.25.1

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.
@@ -19,7 +19,7 @@ export type GamepadFirstPersonControlsOptions = GamepadControlsOptions & {
19
19
  */
20
20
  lookSpeed: number;
21
21
  /**
22
- * Movement stick axes and processing pipeline.
22
+ * Axes and processing pipeline for yaw-based movement in the XZ plane.
23
23
  */
24
24
  moveStick: GamepadStickBindingOptions;
25
25
  /**
@@ -32,12 +32,12 @@ export type GamepadFirstPersonControlsOptions = GamepadControlsOptions & {
32
32
  */
33
33
  buttonDeadzone: number;
34
34
  /**
35
- * Button index for **moving up** (analog trigger value used for proportional speed).
35
+ * Button index for **moving up** along Y (analog value used for proportional speed).
36
36
  * @default 6 - Left trigger
37
37
  */
38
38
  buttonMoveUp: number;
39
39
  /**
40
- * Button index for **moving down** (analog trigger value used for proportional speed).
40
+ * Button index for **moving down** along Y (analog value used for proportional speed).
41
41
  * @default 7 - Right trigger
42
42
  */
43
43
  buttonMoveDown: number;
@@ -47,6 +47,8 @@ export type GamepadFirstPersonControlsOptions = GamepadControlsOptions & {
47
47
  *
48
48
  * Gamepad input is additive with keyboard/mouse input - call
49
49
  * `gamepadControls.update(delta)` before `controls.update(delta)` each frame.
50
+ * Movement follows the native keyboard frame: yaw-based translation in XZ
51
+ * and climbing along Y, independent of camera pitch and roll.
50
52
  * Bindings and speeds are configurable via {@link GamepadFirstPersonControlsOptions}.
51
53
  */
52
54
  export declare class GamepadFirstPersonControls extends GamepadControls {
@@ -26,6 +26,8 @@ const LOOK_SPEED_SCALE = 36e3;
26
26
  *
27
27
  * Gamepad input is additive with keyboard/mouse input - call
28
28
  * `gamepadControls.update(delta)` before `controls.update(delta)` each frame.
29
+ * Movement follows the native keyboard frame: yaw-based translation in XZ
30
+ * and climbing along Y, independent of camera pitch and roll.
29
31
  * Bindings and speeds are configurable via {@link GamepadFirstPersonControlsOptions}.
30
32
  */
31
33
  var GamepadFirstPersonControls = class extends GamepadControls {
@@ -64,7 +66,9 @@ var GamepadFirstPersonControls = class extends GamepadControls {
64
66
  this.#applyLook(deltaTime, lookSpeed, lookStick);
65
67
  }
66
68
  /**
67
- * Applies local translation input to FirstPersonControls' object.
69
+ * 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.
68
72
  *
69
73
  * @param deltaTime - Seconds since the last frame.
70
74
  * @param moveSpeed - User-configured movement speed multiplier.
@@ -78,21 +82,24 @@ var GamepadFirstPersonControls = class extends GamepadControls {
78
82
  const input = this.gamepadInput;
79
83
  const moveMult = deltaTime * controls.movementSpeed * moveSpeed;
80
84
  const move = input.stick(moveStick.xAxis, moveStick.yAxis, moveStick.pipeline);
81
- const forward = move.y;
82
- if (forward !== 0) {
83
- let distance = forward * moveMult;
84
- if (forward < 0 && controls.heightSpeed) {
85
+ if (move.x !== 0 || move.y !== 0) {
86
+ const yaw = MathUtils.degToRad(this.#getOrientation().lon);
87
+ const sinYaw = Math.sin(yaw);
88
+ const cosYaw = Math.cos(yaw);
89
+ const forward = -move.y;
90
+ let forwardDistance = forward * moveMult;
91
+ if (forward > 0 && controls.heightSpeed) {
85
92
  const heightDelta = MathUtils.clamp(controls.object.position.y, controls.heightMin, controls.heightMax) - controls.heightMin;
86
- distance -= -forward * deltaTime * heightDelta * controls.heightCoef * moveSpeed;
93
+ forwardDistance += forward * deltaTime * heightDelta * controls.heightCoef * moveSpeed;
87
94
  }
88
- controls.object.translateZ(distance);
95
+ const strafeDistance = move.x * moveMult;
96
+ controls.object.position.x += sinYaw * forwardDistance - cosYaw * strafeDistance;
97
+ controls.object.position.z += cosYaw * forwardDistance + sinYaw * strafeDistance;
89
98
  }
90
- const strafe = move.x;
91
- if (strafe !== 0) controls.object.translateX(strafe * moveMult);
92
99
  const up = input.buttonValue(buttonMoveUp);
93
100
  const down = input.buttonValue(buttonMoveDown);
94
- if (up > buttonDeadzone) controls.object.translateY(up * moveMult);
95
- if (down > buttonDeadzone) controls.object.translateY(-down * moveMult);
101
+ const climb = (up > buttonDeadzone ? up : 0) - (down > buttonDeadzone ? down : 0);
102
+ if (climb !== 0) controls.object.position.y += climb * moveMult;
96
103
  }
97
104
  /**
98
105
  * Applies camera look input while keeping FirstPersonControls state in sync.
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.0",
4
+ "version": "0.25.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/luckasnix/three-gamepad-controls#readme",
7
7
  "author": {