Spaces:
Running
Running
cutechicken
commited on
Commit
β’
6bacfac
1
Parent(s):
254f9c3
Update game.js
Browse files
game.js
CHANGED
@@ -106,23 +106,9 @@ class TankPlayer {
|
|
106 |
update(mouseX, mouseY, scene) {
|
107 |
if (!this.body || !this.turretGroup) return;
|
108 |
|
109 |
-
//
|
110 |
-
|
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 |
|
127 |
// νλ μ΄μ΄ μ΄μ μ
λ°μ΄νΈ
|
128 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
@@ -499,9 +485,10 @@ async addDesertDecorations() {
|
|
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
|
504 |
-
|
|
|
505 |
|
506 |
// κ°λ μ κ·ν (-Ο ~ Ο)
|
507 |
while (this.mouse.x > Math.PI) this.mouse.x -= Math.PI * 2;
|
@@ -557,24 +544,11 @@ async addDesertDecorations() {
|
|
557 |
const cameraDistance = 30;
|
558 |
const cameraHeight = 15;
|
559 |
|
560 |
-
//
|
561 |
-
const
|
562 |
-
|
563 |
-
// νμ¬ μΉ΄λ©λΌ κ°λμ λͺ©ν κ°λ μ¬μ΄μ λΆλλ¬μ΄ μ ν
|
564 |
-
const currentCameraAngle = Math.atan2(
|
565 |
-
this.camera.position.x - tankPos.x,
|
566 |
-
this.camera.position.z - tankPos.z
|
567 |
-
);
|
568 |
-
|
569 |
-
let angleDiff = targetAngle + Math.PI - currentCameraAngle;
|
570 |
-
while (angleDiff > Math.PI) angleDiff -= Math.PI * 2;
|
571 |
-
while (angleDiff < -Math.PI) angleDiff += Math.PI * 2;
|
572 |
-
|
573 |
-
const smoothing = 0.1;
|
574 |
-
const newCameraAngle = currentCameraAngle + angleDiff * smoothing;
|
575 |
|
576 |
-
const cameraX = tankPos.x + Math.sin(
|
577 |
-
const cameraZ = tankPos.z + Math.cos(
|
578 |
|
579 |
this.camera.position.set(
|
580 |
cameraX,
|
|
|
106 |
update(mouseX, mouseY, scene) {
|
107 |
if (!this.body || !this.turretGroup) return;
|
108 |
|
109 |
+
// μΉ΄λ©λΌ λ°©ν₯μΌλ‘ ν¬ν νμ
|
110 |
+
this.turretGroup.rotation.y = mouseX;
|
111 |
+
this.turretRotation = mouseX + this.body.rotation.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
// νλ μ΄μ΄ μ΄μ μ
λ°μ΄νΈ
|
114 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
|
|
485 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
486 |
|
487 |
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
488 |
+
// μΉ΄λ©λΌ νμ λμ
|
489 |
+
this.mouse.x += movementX * 0.002;
|
490 |
+
// XμΆ νμ λ§ μ¬μ©νλ―λ‘ YμΆμ 0μΌλ‘ μ μ§
|
491 |
+
this.mouse.y = 0;
|
492 |
|
493 |
// κ°λ μ κ·ν (-Ο ~ Ο)
|
494 |
while (this.mouse.x > Math.PI) this.mouse.x -= Math.PI * 2;
|
|
|
544 |
const cameraDistance = 30;
|
545 |
const cameraHeight = 15;
|
546 |
|
547 |
+
// λ§μ°μ€ X κ°μ μΉ΄λ©λΌ κ°λλ‘ μ¬μ©
|
548 |
+
const cameraAngle = this.mouse.x + Math.PI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
|
550 |
+
const cameraX = tankPos.x + Math.sin(cameraAngle) * cameraDistance;
|
551 |
+
const cameraZ = tankPos.z + Math.cos(cameraAngle) * cameraDistance;
|
552 |
|
553 |
this.camera.position.set(
|
554 |
cameraX,
|