Spaces:
Running
Running
cutechicken
commited on
Commit
โข
a7b799c
1
Parent(s):
4742d91
Update game.js
Browse files
game.js
CHANGED
@@ -102,14 +102,14 @@ class TankPlayer {
|
|
102 |
return bullet;
|
103 |
}
|
104 |
|
105 |
-
|
|
|
106 |
if (!this.body || !this.turretGroup) return;
|
107 |
|
108 |
-
//
|
109 |
-
const
|
110 |
-
const mousePosition = new THREE.Vector2(mouseX, mouseY);
|
111 |
-
const angle = Math.atan2(mousePosition.x - screenCenter.x, mousePosition.y - screenCenter.y);
|
112 |
this.turretGroup.rotation.y = angle;
|
|
|
113 |
|
114 |
// ํ๋ ์ด์ด ์ด์ ์
๋ฐ์ดํธ
|
115 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
@@ -540,23 +540,29 @@ async addDesertDecorations() {
|
|
540 |
this.tank.move(direction);
|
541 |
}
|
542 |
|
543 |
-
//
|
544 |
const tankPos = this.tank.getPosition();
|
545 |
-
const
|
|
|
|
|
546 |
const cameraDistance = 30;
|
547 |
const cameraHeight = 15;
|
|
|
|
|
|
|
|
|
548 |
|
549 |
-
//
|
550 |
this.camera.position.set(
|
551 |
-
|
552 |
tankPos.y + cameraHeight,
|
553 |
-
|
554 |
);
|
555 |
|
556 |
-
// ์นด๋ฉ๋ผ๊ฐ
|
557 |
this.camera.lookAt(new THREE.Vector3(
|
558 |
tankPos.x,
|
559 |
-
tankPos.y,
|
560 |
tankPos.z
|
561 |
));
|
562 |
}
|
|
|
102 |
return bullet;
|
103 |
}
|
104 |
|
105 |
+
// TankPlayer ํด๋์ค ๋ด๋ถ
|
106 |
+
update(mouseX, mouseY, scene) {
|
107 |
if (!this.body || !this.turretGroup) return;
|
108 |
|
109 |
+
// ๋ง์ฐ์ค ๋ฐฉํฅ์ผ๋ก ํฌํ ํ์
|
110 |
+
const angle = Math.atan2(mouseX, mouseY);
|
|
|
|
|
111 |
this.turretGroup.rotation.y = angle;
|
112 |
+
this.turretRotation = angle; // ํ์ฌ ํฌํ ํ์ ๊ฐ๋ ์ ์ฅ
|
113 |
|
114 |
// ํ๋ ์ด์ด ์ด์ ์
๋ฐ์ดํธ
|
115 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
|
|
540 |
this.tank.move(direction);
|
541 |
}
|
542 |
|
543 |
+
// ํฑํฌ์ ํฌํ์ ํ์ฌ ์์น/ํ์ ๊ฐ์ ธ์ค๊ธฐ
|
544 |
const tankPos = this.tank.getPosition();
|
545 |
+
const turretRotation = this.tank.turretRotation;
|
546 |
+
|
547 |
+
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ
|
548 |
const cameraDistance = 30;
|
549 |
const cameraHeight = 15;
|
550 |
+
|
551 |
+
// ํฌํ ํ์ ์ ๊ธฐ์ค์ผ๋ก ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ (ํฌํ์ ๋ฐ๋ํธ)
|
552 |
+
const cameraX = tankPos.x - Math.sin(turretRotation + Math.PI) * cameraDistance;
|
553 |
+
const cameraZ = tankPos.z - Math.cos(turretRotation + Math.PI) * cameraDistance;
|
554 |
|
555 |
+
// ์นด๋ฉ๋ผ ์์น ์ค์
|
556 |
this.camera.position.set(
|
557 |
+
cameraX,
|
558 |
tankPos.y + cameraHeight,
|
559 |
+
cameraZ
|
560 |
);
|
561 |
|
562 |
+
// ์นด๋ฉ๋ผ๊ฐ ํฑํฌ๋ฅผ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
563 |
this.camera.lookAt(new THREE.Vector3(
|
564 |
tankPos.x,
|
565 |
+
tankPos.y + 2, // ์ฝ๊ฐ ์๋ก ์ฌ๋ ค์ ํฌํ์ ๋ ์ ๋ณด์ด๊ฒ ํจ
|
566 |
tankPos.z
|
567 |
));
|
568 |
}
|