cutechicken commited on
Commit
60a61a4
Β·
verified Β·
1 Parent(s): ca7a3bc

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +34 -27
game.js CHANGED
@@ -106,21 +106,18 @@ class TankPlayer {
106
  update(mouseX, mouseY, scene) {
107
  if (!this.body || !this.turretGroup) return;
108
 
109
- // 마우슀 이동에 λ”°λ₯Έ 포탑 νšŒμ „
110
- // 차체의 νšŒμ „μ„ κ³ λ €ν•˜μ—¬ μƒλŒ€μ μΈ 포탑 νšŒμ „ 계산
111
- let targetAngle = Math.atan2(mouseX, mouseY);
112
- if (targetAngle < 0) targetAngle += Math.PI * 2;
113
-
114
- // 차체의 ν˜„μž¬ νšŒμ „κ°’μ„ κ³ λ €ν•˜μ—¬ ν¬νƒ‘μ˜ μƒλŒ€ νšŒμ „ 계산
115
- let relativeAngle = targetAngle - this.body.rotation.y;
116
 
117
- // 각도λ₯Ό -Ο€μ—μ„œ Ο€ μ‚¬μ΄λ‘œ μ •κ·œν™”
118
- while (relativeAngle > Math.PI) relativeAngle -= Math.PI * 2;
119
- while (relativeAngle < -Math.PI) relativeAngle += Math.PI * 2;
120
-
121
- // 포탑 νšŒμ „ μ œν•œ μ—†μŒ (360도 νšŒμ „ κ°€λŠ₯)
122
- this.turretGroup.rotation.y = relativeAngle;
123
- this.turretRotation = targetAngle; // 전체 νšŒμ „κ° μ €μž₯
 
 
124
 
125
  // ν”Œλ ˆμ΄μ–΄ μ΄μ•Œ μ—…λ°μ΄νŠΈ
126
  for (let i = this.bullets.length - 1; i >= 0; i--) {
@@ -493,17 +490,16 @@ async addDesertDecorations() {
493
  }
494
  });
495
 
496
- document.addEventListener('mousemove', (event) => {
497
  if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
498
 
499
- // 마우슀 μ›€μ§μž„μ„ ν™”λ©΄ 쀑앙 κΈ°μ€€μœΌλ‘œ μ •κ·œν™”
500
  const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
501
- const movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
502
-
503
- this.mouse.x += movementX * 0.002;
504
- this.mouse.y += movementY * 0.002;
505
 
506
- // 마우슀 이동
 
 
507
  });
508
 
509
 
@@ -555,14 +551,25 @@ async addDesertDecorations() {
555
  const cameraDistance = 30;
556
  const cameraHeight = 15;
557
 
558
- // 포탑 전체 νšŒμ „κ° μ‚¬μš© (차체 νšŒμ „ + 포탑 μƒλŒ€ νšŒμ „)
559
- const totalRotation = this.tank.body.rotation.y + this.tank.turretGroup.rotation.y;
560
- const cameraAngle = totalRotation + Math.PI;
 
 
 
 
 
 
 
 
 
 
 
 
561
 
562
- const cameraX = tankPos.x + Math.sin(cameraAngle) * cameraDistance;
563
- const cameraZ = tankPos.z + Math.cos(cameraAngle) * cameraDistance;
564
 
565
- // 카메라 μœ„μΉ˜ 및 μ‹œμ  μ„€μ •
566
  this.camera.position.set(
567
  cameraX,
568
  tankPos.y + cameraHeight,
 
106
  update(mouseX, mouseY, scene) {
107
  if (!this.body || !this.turretGroup) return;
108
 
109
+ // ν¬νƒ‘μ˜ ν˜„μž¬ νšŒμ „κ°λ„
110
+ const currentRotation = this.turretGroup.rotation.y;
 
 
 
 
 
111
 
112
+ // λͺ©ν‘œ νšŒμ „κ°λ„ (차체 νšŒμ „ κ³ λ €)
113
+ const targetRotation = mouseX;
114
+
115
+ // λΆ€λ“œλŸ¬μš΄ νšŒμ „μ„ μœ„ν•œ 보간
116
+ const rotationSpeed = 0.1;
117
+ const newRotation = currentRotation + (targetRotation - currentRotation) * rotationSpeed;
118
+
119
+ this.turretGroup.rotation.y = newRotation;
120
+ this.turretRotation = newRotation + this.body.rotation.y; // 전체 νšŒμ „κ° μ €μž₯
121
 
122
  // ν”Œλ ˆμ΄μ–΄ μ΄μ•Œ μ—…λ°μ΄νŠΈ
123
  for (let i = this.bullets.length - 1; i >= 0; i--) {
 
490
  }
491
  });
492
 
493
+ ddocument.addEventListener('mousemove', (event) => {
494
  if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
495
 
 
496
  const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
497
+ this.mouse.x += movementX * 0.002; // λˆ„μ  νšŒμ „λŸ‰μœΌλ‘œ λ³€κ²½
498
+ this.mouse.y = 0; // Y좕은 μ‚¬μš©ν•˜μ§€ μ•ŠμŒ
 
 
499
 
500
+ // 각도 μ •κ·œν™” (-Ο€ ~ Ο€)
501
+ while (this.mouse.x > Math.PI) this.mouse.x -= Math.PI * 2;
502
+ while (this.mouse.x < -Math.PI) this.mouse.x += Math.PI * 2;
503
  });
504
 
505
 
 
551
  const cameraDistance = 30;
552
  const cameraHeight = 15;
553
 
554
+ // ν¬νƒ‘μ˜ νšŒμ „κ° μ‚¬μš©
555
+ const targetAngle = this.tank.turretRotation;
556
+
557
+ // ν˜„μž¬ 카메라 각도와 λͺ©ν‘œ 각도 μ‚¬μ΄μ˜ λΆ€λ“œλŸ¬μš΄ μ „ν™˜
558
+ const currentCameraAngle = Math.atan2(
559
+ this.camera.position.x - tankPos.x,
560
+ this.camera.position.z - tankPos.z
561
+ );
562
+
563
+ let angleDiff = targetAngle + Math.PI - currentCameraAngle;
564
+ while (angleDiff > Math.PI) angleDiff -= Math.PI * 2;
565
+ while (angleDiff < -Math.PI) angleDiff += Math.PI * 2;
566
+
567
+ const smoothing = 0.1;
568
+ const newCameraAngle = currentCameraAngle + angleDiff * smoothing;
569
 
570
+ const cameraX = tankPos.x + Math.sin(newCameraAngle) * cameraDistance;
571
+ const cameraZ = tankPos.z + Math.cos(newCameraAngle) * cameraDistance;
572
 
 
573
  this.camera.position.set(
574
  cameraX,
575
  tankPos.y + cameraHeight,