three-base 2.0.124 → 2.0.125

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.
package/FPScontrol.d.ts CHANGED
@@ -22,8 +22,11 @@ export default class FPScontrol extends EventDispatcher {
22
22
  addOctree(obj: Object3D): Octree;
23
23
  playerCollider: Capsule;
24
24
  clock: Clock;
25
+ prePlayerVelocity: Vector3;
25
26
  playerVelocity: Vector3;
27
+ jumping: boolean;
26
28
  playerDirection: Vector3;
29
+ prePlayerOnFloor: boolean;
27
30
  playerOnFloor: boolean;
28
31
  mouseTime: number;
29
32
  isMousedown: boolean;
package/FPScontrol.js CHANGED
@@ -69,8 +69,12 @@ export default class FPScontrol extends EventDispatcher {
69
69
  playerCollider = new Capsule(new Vector3(0, 0.35, 0), new Vector3(0, 1, 0), 0.35);
70
70
  // 时钟对象
71
71
  clock = new Clock();
72
+ prePlayerVelocity = new Vector3();
72
73
  playerVelocity = new Vector3();
74
+ // 起跳中
75
+ jumping = false;
73
76
  playerDirection = new Vector3();
77
+ prePlayerOnFloor = false;
74
78
  playerOnFloor = false;
75
79
  mouseTime = 0;
76
80
  isMousedown = false;
@@ -139,7 +143,8 @@ export default class FPScontrol extends EventDispatcher {
139
143
  !this.keyStates["KeyS"] &&
140
144
  !this.keyStates["KeyA"] &&
141
145
  !this.keyStates["KeyD"]) {
142
- if (!this.inertia) { // 关闭惯性时就大幅增加动能的衰减
146
+ if (!this.inertia) {
147
+ // 关闭惯性时就大幅增加动能的衰减
143
148
  this.playerVelocity.x *= 0.85;
144
149
  this.playerVelocity.z *= 0.85;
145
150
  }
@@ -147,6 +152,8 @@ export default class FPScontrol extends EventDispatcher {
147
152
  if (this.playerOnFloor) {
148
153
  if (this.keyStates["Space"]) {
149
154
  this.playerVelocity.y = 15;
155
+ this.jumping = true;
156
+ this.dispatchEvent({ type: "jump_start" });
150
157
  }
151
158
  }
152
159
  };
@@ -174,8 +181,23 @@ export default class FPScontrol extends EventDispatcher {
174
181
  if (!this.playerOnFloor) {
175
182
  this.playerVelocity.addScaledVector(result.normal, -result.normal.dot(this.playerVelocity));
176
183
  }
184
+ const { x: preX, y: preY, z: preZ } = this.prePlayerVelocity;
185
+ const { x, y, z } = this.playerVelocity;
186
+ if (Math.abs(preX + preZ) < 0.1 && Math.abs(x + z) > 0.1) {
187
+ this.dispatchEvent({ type: "move_start" });
188
+ }
189
+ else if (Math.abs(preX + preZ) > 0.1 && Math.abs(x + z) < 0.1) {
190
+ this.dispatchEvent({ type: "move_end" });
191
+ }
192
+ this.prePlayerVelocity.copy(this.playerVelocity);
177
193
  this.playerCollider.translate(result.normal.multiplyScalar(result.depth));
178
194
  }
195
+ if (this.jumping && !this.prePlayerOnFloor && this.playerOnFloor) {
196
+ // 分发落地事件
197
+ this.jumping = false;
198
+ this.dispatchEvent({ type: "jump_end" });
199
+ }
200
+ this.prePlayerOnFloor = this.playerOnFloor;
179
201
  }
180
202
  // 更新控制器的位置
181
203
  teleportPlayerIfOob = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "2.0.124",
3
+ "version": "2.0.125",
4
4
  "description": "three 3d three-base",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"