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(