cutechicken commited on
Commit
612e991
โ€ข
1 Parent(s): fa41962

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +20 -16
game.js CHANGED
@@ -444,7 +444,7 @@ class Game {
444
  });
445
  }
446
 
447
- handleMovement() {
448
  if (!this.tank.isLoaded) return;
449
 
450
  const direction = new THREE.Vector3();
@@ -475,26 +475,30 @@ class Game {
475
  this.tank.turretGroup.rotation.y = rotationAngle;
476
  }
477
 
478
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ๋ฐ ํšŒ์ „ ์—…๋ฐ์ดํŠธ
479
  const tankPos = this.tank.getPosition();
480
- const cameraDistance = 20;
481
- const cameraHeight = 10;
 
482
 
483
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ
484
  const tankRotation = this.tank.body.rotation.y;
485
- const cameraOffset = new THREE.Vector3(
486
- Math.sin(tankRotation) * cameraDistance,
487
- cameraHeight,
488
- Math.cos(tankRotation) * cameraDistance
 
 
 
 
 
 
 
 
 
489
  );
490
 
491
- this.camera.position.copy(tankPos).sub(cameraOffset);
492
- // ํƒฑํฌ์˜ ์ƒ๋‹จ์„ ๋ฐ”๋ผ๋ณด๋„๋ก ์ˆ˜์ •
493
- this.camera.lookAt(new THREE.Vector3(
494
- tankPos.x,
495
- tankPos.y + 2, // ํƒฑํฌ์˜ ์ƒ๋‹จ ๋ถ€๋ถ„์„ ๋ฐ”๋ผ๋ณด๋„๋ก
496
- tankPos.z
497
- ));
498
  }
499
  createBuildings() {
500
  const buildingTypes = [
 
444
  });
445
  }
446
 
447
+ handleMovement() {
448
  if (!this.tank.isLoaded) return;
449
 
450
  const direction = new THREE.Vector3();
 
475
  this.tank.turretGroup.rotation.y = rotationAngle;
476
  }
477
 
478
+ // ์—ฌ๊ธฐ๋ถ€ํ„ฐ ์นด๋ฉ”๋ผ ๋กœ์ง์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค
479
  const tankPos = this.tank.getPosition();
480
+ const cameraDistance = 30; // ์นด๋ฉ”๋ผ์™€ ํƒฑํฌ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ
481
+ const cameraHeight = 15; // ์นด๋ฉ”๋ผ์˜ ๋†’์ด
482
+ const lookAtHeight = 5; // ์นด๋ฉ”๋ผ๊ฐ€ ๋ฐ”๋ผ๋ณด๋Š” ๋†’์ด
483
 
484
+ // ํƒฑํฌ์˜ ํšŒ์ „์— ๋”ฐ๋ผ ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ
485
  const tankRotation = this.tank.body.rotation.y;
486
+
487
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ ์ˆ˜์ •
488
+ this.camera.position.set(
489
+ tankPos.x - Math.sin(tankRotation) * cameraDistance,
490
+ tankPos.y + cameraHeight,
491
+ tankPos.z - Math.cos(tankRotation) * cameraDistance
492
+ );
493
+
494
+ // ์นด๋ฉ”๋ผ๊ฐ€ ๋ฐ”๋ผ๋ณด๋Š” ์ง€์ ์„ ํƒฑํฌ ์œ„์น˜๋ณด๋‹ค ์•ฝ๊ฐ„ ์•ž์ชฝ์œผ๋กœ ์„ค์ •
495
+ const lookAtPoint = new THREE.Vector3(
496
+ tankPos.x + Math.sin(tankRotation) * 10, // ํƒฑํฌ ์•ž์ชฝ 10 ์œ ๋‹›
497
+ tankPos.y + lookAtHeight, // ํƒฑํฌ๋ณด๋‹ค ์•ฝ๊ฐ„ ์œ„
498
+ tankPos.z + Math.cos(tankRotation) * 10 // ํƒฑํฌ ์•ž์ชฝ 10 ์œ ๋‹›
499
  );
500
 
501
+ this.camera.lookAt(lookAtPoint);
 
 
 
 
 
 
502
  }
503
  createBuildings() {
504
  const buildingTypes = [