Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -109,13 +109,18 @@ update(mouseX, mouseY, scene) {
|
|
| 109 |
// ν¬νμ νμ¬ νμ κ°λ
|
| 110 |
const currentRotation = this.turretGroup.rotation.y;
|
| 111 |
|
| 112 |
-
//
|
| 113 |
-
const
|
| 114 |
|
| 115 |
-
//
|
| 116 |
-
|
| 117 |
-
const newRotation = currentRotation + (targetRotation - currentRotation) * rotationSpeed;
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
this.turretGroup.rotation.y = newRotation;
|
| 120 |
this.turretRotation = newRotation + this.body.rotation.y; // μ 체 νμ κ° μ μ₯
|
| 121 |
|
|
@@ -490,11 +495,12 @@ async addDesertDecorations() {
|
|
| 490 |
}
|
| 491 |
});
|
| 492 |
|
| 493 |
-
|
| 494 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
| 495 |
|
| 496 |
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
| 497 |
-
|
|
|
|
| 498 |
this.mouse.y = 0; // YμΆμ μ¬μ©νμ§ μμ
|
| 499 |
|
| 500 |
// κ°λ μ κ·ν (-Ο ~ Ο)
|
|
|
|
| 109 |
// ν¬νμ νμ¬ νμ κ°λ
|
| 110 |
const currentRotation = this.turretGroup.rotation.y;
|
| 111 |
|
| 112 |
+
// λ§μ°μ€ μ΄λλμ νμ λͺ©νλμΌλ‘ λ³ν
|
| 113 |
+
const rotationTarget = mouseX * 0.05; // νμ μλ κ°μ
|
| 114 |
|
| 115 |
+
// νμ¬ κ°λμ λͺ©ν κ°λμ μ°¨μ΄ κ³μ°
|
| 116 |
+
let angleDiff = rotationTarget;
|
|
|
|
| 117 |
|
| 118 |
+
// κ°λ μ°¨μ΄κ° νΉμ μκ³κ°λ³΄λ€ μμΌλ©΄ μ²μ²ν νμ
|
| 119 |
+
const maxRotationSpeed = 0.03; // μ΅λ νμ μλ
|
| 120 |
+
const rotationAmount = Math.sign(angleDiff) * Math.min(Math.abs(angleDiff), maxRotationSpeed);
|
| 121 |
+
|
| 122 |
+
// μλ‘μ΄ νμ κ° κ³μ° λ° μ μ©
|
| 123 |
+
const newRotation = currentRotation + rotationAmount;
|
| 124 |
this.turretGroup.rotation.y = newRotation;
|
| 125 |
this.turretRotation = newRotation + this.body.rotation.y; // μ 체 νμ κ° μ μ₯
|
| 126 |
|
|
|
|
| 495 |
}
|
| 496 |
});
|
| 497 |
|
| 498 |
+
document.addEventListener('mousemove', (event) => {
|
| 499 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
| 500 |
|
| 501 |
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
| 502 |
+
// λ§μ°μ€ μ΄λλμ λ μμ κ°μΌλ‘ μ‘°μ
|
| 503 |
+
this.mouse.x = movementX * 0.001; // κ°λ κ°μ
|
| 504 |
this.mouse.y = 0; // YμΆμ μ¬μ©νμ§ μμ
|
| 505 |
|
| 506 |
// κ°λ μ κ·ν (-Ο ~ Ο)
|