cutechicken commited on
Commit
a7b799c
โ€ข
1 Parent(s): 4742d91

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +18 -12
game.js CHANGED
@@ -102,14 +102,14 @@ class TankPlayer {
102
  return bullet;
103
  }
104
 
105
- update(mouseX, mouseY, scene) {
 
106
  if (!this.body || !this.turretGroup) return;
107
 
108
- // ํฌํƒ‘ ํšŒ์ „ - ๋งˆ์šฐ์Šค ์œ„์น˜์— ๋”ฐ๋ผ ํšŒ์ „
109
- const screenCenter = new THREE.Vector2(0, 0);
110
- const mousePosition = new THREE.Vector2(mouseX, mouseY);
111
- const angle = Math.atan2(mousePosition.x - screenCenter.x, mousePosition.y - screenCenter.y);
112
  this.turretGroup.rotation.y = angle;
 
113
 
114
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์—…๋ฐ์ดํŠธ
115
  for (let i = this.bullets.length - 1; i >= 0; i--) {
@@ -540,23 +540,29 @@ async addDesertDecorations() {
540
  this.tank.move(direction);
541
  }
542
 
543
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ์—…๋ฐ์ดํŠธ - ํ•ญ์ƒ ํƒฑํฌ ๋’ค์—์„œ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
544
  const tankPos = this.tank.getPosition();
545
- const tankRotation = this.tank.body.rotation.y;
 
 
546
  const cameraDistance = 30;
547
  const cameraHeight = 15;
 
 
 
 
548
 
549
- // ํƒฑํฌ์˜ ๋’ค์ชฝ ์œ„์น˜์— ์นด๋ฉ”๋ผ ๋ฐฐ์น˜
550
  this.camera.position.set(
551
- tankPos.x - Math.sin(tankRotation) * cameraDistance,
552
  tankPos.y + cameraHeight,
553
- tankPos.z - Math.cos(tankRotation) * cameraDistance
554
  );
555
 
556
- // ์นด๋ฉ”๋ผ๊ฐ€ ํ•ญ์ƒ ํƒฑํฌ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
557
  this.camera.lookAt(new THREE.Vector3(
558
  tankPos.x,
559
- tankPos.y,
560
  tankPos.z
561
  ));
562
  }
 
102
  return bullet;
103
  }
104
 
105
+ // TankPlayer ํด๋ž˜์Šค ๋‚ด๋ถ€
106
+ update(mouseX, mouseY, scene) {
107
  if (!this.body || !this.turretGroup) return;
108
 
109
+ // ๋งˆ์šฐ์Šค ๋ฐฉํ–ฅ์œผ๋กœ ํฌํƒ‘ ํšŒ์ „
110
+ const angle = Math.atan2(mouseX, mouseY);
 
 
111
  this.turretGroup.rotation.y = angle;
112
+ this.turretRotation = angle; // ํ˜„์žฌ ํฌํƒ‘ ํšŒ์ „ ๊ฐ๋„ ์ €์žฅ
113
 
114
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์—…๋ฐ์ดํŠธ
115
  for (let i = this.bullets.length - 1; i >= 0; i--) {
 
540
  this.tank.move(direction);
541
  }
542
 
543
+ // ํƒฑํฌ์™€ ํฌํƒ‘์˜ ํ˜„์žฌ ์œ„์น˜/ํšŒ์ „ ๊ฐ€์ ธ์˜ค๊ธฐ
544
  const tankPos = this.tank.getPosition();
545
+ const turretRotation = this.tank.turretRotation;
546
+
547
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ
548
  const cameraDistance = 30;
549
  const cameraHeight = 15;
550
+
551
+ // ํฌํƒ‘ ํšŒ์ „์„ ๊ธฐ์ค€์œผ๋กœ ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ (ํฌํƒ‘์˜ ๋ฐ˜๋Œ€ํŽธ)
552
+ const cameraX = tankPos.x - Math.sin(turretRotation + Math.PI) * cameraDistance;
553
+ const cameraZ = tankPos.z - Math.cos(turretRotation + Math.PI) * cameraDistance;
554
 
555
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ์„ค์ •
556
  this.camera.position.set(
557
+ cameraX,
558
  tankPos.y + cameraHeight,
559
+ cameraZ
560
  );
561
 
562
+ // ์นด๋ฉ”๋ผ๊ฐ€ ํƒฑํฌ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
563
  this.camera.lookAt(new THREE.Vector3(
564
  tankPos.x,
565
+ tankPos.y + 2, // ์•ฝ๊ฐ„ ์œ„๋กœ ์˜ฌ๋ ค์„œ ํฌํƒ‘์„ ๋” ์ž˜ ๋ณด์ด๊ฒŒ ํ•จ
566
  tankPos.z
567
  ));
568
  }