cutechicken commited on
Commit
75e2037
ยท
verified ยท
1 Parent(s): 168be5c

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +10 -17
game.js CHANGED
@@ -111,9 +111,8 @@ update(mouseX, mouseY, scene) {
111
  // ๊ฐ๋„๋ฅผ 0~2ฯ€ ๋ฒ”์œ„๋กœ ์ •๊ทœํ™”
112
  if (angle < 0) angle += Math.PI * 2;
113
 
114
- // ํฌํƒ‘ ํšŒ์ „์— 180๋„(ฯ€)๋ฅผ ๋”ํ•ด์„œ ํฌ์‹ ์ด ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์„ ํ–ฅํ•˜๋„๋ก ํ•จ
115
- this.turretGroup.rotation.y = angle + Math.PI;
116
- this.turretRotation = angle + Math.PI;
117
 
118
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์—…๋ฐ์ดํŠธ
119
  for (let i = this.bullets.length - 1; i >= 0; i--) {
@@ -530,20 +529,13 @@ async addDesertDecorations() {
530
 
531
  const direction = new THREE.Vector3();
532
 
533
- // ์ด๋™ ๋ฐฉํ–ฅ ๊ณ„์‚ฐ
534
  if (this.keys.forward) direction.z += 1;
535
  if (this.keys.backward) direction.z -= 1;
536
- if (this.keys.left) direction.x -= 1;
537
- if (this.keys.right) direction.x += 1;
538
 
539
  if (direction.length() > 0) {
540
  direction.normalize();
541
-
542
- // ํƒฑํฌ ํšŒ์ „
543
- if (this.keys.left) this.tank.rotate(-1);
544
- if (this.keys.right) this.tank.rotate(1);
545
-
546
- // ์ด๋™ ๋ฐฉํ–ฅ์„ ํƒฑํฌ์˜ ํšŒ์ „์— ๋งž์ถฐ ์กฐ์ •
547
  direction.applyEuler(this.tank.body.rotation);
548
  this.tank.move(direction);
549
  }
@@ -551,14 +543,15 @@ async addDesertDecorations() {
551
  // ํƒฑํฌ ์œ„์น˜ ๊ฐ€์ ธ์˜ค๊ธฐ
552
  const tankPos = this.tank.getPosition();
553
 
554
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ - ๊ณ ์ •๋œ ๋ฐฉํ–ฅ์œผ๋กœ ์„ค์ •
555
  const cameraDistance = 30;
556
  const cameraHeight = 15;
557
- const fixedCameraAngle = Math.PI; // ์นด๋ฉ”๋ผ๋Š” ํ•ญ์ƒ ๋‚จ์ชฝ(ฯ€)์„ ํ–ฅํ•˜๋„๋ก ์„ค์ •
558
 
559
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ (ํƒฑํฌ ํšŒ์ „๊ณผ ๋…๋ฆฝ์ )
560
- const cameraX = tankPos.x - Math.sin(fixedCameraAngle) * cameraDistance;
561
- const cameraZ = tankPos.z - Math.cos(fixedCameraAngle) * cameraDistance;
 
 
562
 
563
  // ์นด๋ฉ”๋ผ ์œ„์น˜ ๋ฐ ์‹œ์  ์„ค์ •
564
  this.camera.position.set(
 
111
  // ๊ฐ๋„๋ฅผ 0~2ฯ€ ๋ฒ”์œ„๋กœ ์ •๊ทœํ™”
112
  if (angle < 0) angle += Math.PI * 2;
113
 
114
+ this.turretGroup.rotation.y = angle;
115
+ this.turretRotation = angle;
 
116
 
117
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์—…๋ฐ์ดํŠธ
118
  for (let i = this.bullets.length - 1; i >= 0; i--) {
 
529
 
530
  const direction = new THREE.Vector3();
531
 
 
532
  if (this.keys.forward) direction.z += 1;
533
  if (this.keys.backward) direction.z -= 1;
534
+ if (this.keys.left) this.tank.rotate(-1);
535
+ if (this.keys.right) this.tank.rotate(1);
536
 
537
  if (direction.length() > 0) {
538
  direction.normalize();
 
 
 
 
 
 
539
  direction.applyEuler(this.tank.body.rotation);
540
  this.tank.move(direction);
541
  }
 
543
  // ํƒฑํฌ ์œ„์น˜ ๊ฐ€์ ธ์˜ค๊ธฐ
544
  const tankPos = this.tank.getPosition();
545
 
546
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ๊ณ„์‚ฐ
547
  const cameraDistance = 30;
548
  const cameraHeight = 15;
 
549
 
550
+ // ํฌํƒ‘์˜ ํ˜„์žฌ ํšŒ์ „ ๊ฐ๋„์—์„œ 180๋„๋ฅผ ๋”ํ•ด ํ•ญ์ƒ ํฌํƒ‘์˜ ๋’ค์— ์œ„์น˜ํ•˜๋„๋ก ํ•จ
551
+ const cameraAngle = this.tank.turretRotation + Math.PI;
552
+
553
+ const cameraX = tankPos.x + Math.sin(cameraAngle) * cameraDistance;
554
+ const cameraZ = tankPos.z + Math.cos(cameraAngle) * cameraDistance;
555
 
556
  // ์นด๋ฉ”๋ผ ์œ„์น˜ ๋ฐ ์‹œ์  ์„ค์ •
557
  this.camera.position.set(