three-player-controller 0.3.8 → 0.3.9

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/dist/index.mjs CHANGED
@@ -1005,8 +1005,7 @@ var PlayerController = class {
1005
1005
  // 初始化加载器
1006
1006
  async initLoader() {
1007
1007
  const dracoLoader = new DRACOLoader();
1008
- dracoLoader.setDecoderPath("https://unpkg.com/three@0.180.0/examples/jsm/libs/draco/gltf/");
1009
- dracoLoader.setDecoderConfig({ type: "js" });
1008
+ dracoLoader.setDecoderPath("https://unpkg.com/three@0.182.0/examples/jsm/libs/draco/gltf/");
1010
1009
  this.loader.setDRACOLoader(dracoLoader);
1011
1010
  }
1012
1011
  // 初始化物理引擎
@@ -1079,12 +1078,12 @@ var PlayerController = class {
1079
1078
  action.setEffectiveWeight(0);
1080
1079
  this.personActions.set(actionName, action);
1081
1080
  }
1082
- this.personActions.get("idle").setEffectiveWeight(1);
1083
- this.personActions.get("idle").play();
1081
+ this.personActions.get("idle")?.setEffectiveWeight(1);
1082
+ this.personActions.get("idle")?.play();
1084
1083
  this.actionState = this.personActions.get("idle");
1085
1084
  this.personMixer.addEventListener("finished", (ev) => {
1086
1085
  const done = ev.action;
1087
- if (done === this.personActions.get("jumping")) {
1086
+ if (done === this.personActions?.get("jumping")) {
1088
1087
  if (this.fwdPressed) {
1089
1088
  this.playPersonAnimationByName(this.shiftPressed ? "running" : "walking");
1090
1089
  return;
@@ -1405,15 +1404,13 @@ var PlayerController = class {
1405
1404
  changeView() {
1406
1405
  this.isFirstPerson = !this.isFirstPerson;
1407
1406
  if (this.isFirstPerson) {
1408
- const camWorldDir = new THREE4.Vector3();
1409
- this.camera.getWorldDirection(camWorldDir);
1410
- const flatDir = new THREE4.Vector3(camWorldDir.x, 0, camWorldDir.z).normalize();
1407
+ const playerFwd = new THREE4.Vector3(0, 0, 1).applyQuaternion(this.player.quaternion);
1408
+ const flatDir = new THREE4.Vector3(playerFwd.x, 0, playerFwd.z).normalize();
1411
1409
  if (flatDir.lengthSq() > 1e-3) {
1412
1410
  const yAngle = Math.atan2(flatDir.x, flatDir.z);
1413
- this.player.rotation.set(0, yAngle + Math.PI, 0);
1411
+ this.player.rotation.set(0, yAngle, 0);
1414
1412
  }
1415
- const vertAngle = Math.asin(THREE4.MathUtils.clamp(-camWorldDir.y, -1, 1));
1416
- this.setFirstPersonCamera(vertAngle);
1413
+ this.setFirstPersonCamera();
1417
1414
  this.setOverShoulderView(false);
1418
1415
  } else {
1419
1416
  this.controls.enabled = true;