Spaces:
Running
Running
cutechicken
commited on
Commit
โข
68a71f4
1
Parent(s):
d50b5f8
Update game.js
Browse files
game.js
CHANGED
@@ -363,8 +363,8 @@ class Game {
|
|
363 |
}
|
364 |
|
365 |
// ์นด๋ฉ๋ผ ์ค์ ์์
|
366 |
-
this.camera.position.set(
|
367 |
-
|
368 |
|
369 |
// ๋ก๋ฉ ์๋ฃ
|
370 |
this.isLoading = false;
|
@@ -442,22 +442,22 @@ class Game {
|
|
442 |
if (this.keys.left) direction.x -= 1;
|
443 |
if (this.keys.right) direction.x += 1;
|
444 |
|
|
|
445 |
if (direction.length() > 0) {
|
446 |
direction.normalize();
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
direction.applyEuler(this.tank.body.rotation);
|
448 |
this.tank.move(direction);
|
449 |
-
|
450 |
-
// ํฑํฌ ๋ณธ์ฒด ํ์
|
451 |
-
if (Math.abs(direction.z) > 0 || Math.abs(direction.x) > 0) {
|
452 |
-
const angle = Math.atan2(direction.x, direction.z);
|
453 |
-
this.tank.body.rotation.y = angle;
|
454 |
-
}
|
455 |
}
|
456 |
|
457 |
// ๋ง์ฐ์ค ์์น๋ฅผ ํฑํฌ ๊ธฐ์ค์ผ๋ก ๋ณํ
|
458 |
-
const tankRotation = this.tank.body.rotation.y;
|
459 |
const mouseVector = new THREE.Vector2(this.mouse.x, -this.mouse.y);
|
460 |
-
const rotationAngle = Math.atan2(mouseVector.x, mouseVector.y)
|
461 |
|
462 |
// ํฌํ ํ์
|
463 |
if (this.tank.turretGroup) {
|
@@ -470,11 +470,12 @@ class Game {
|
|
470 |
const cameraHeight = 10;
|
471 |
|
472 |
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ
|
|
|
473 |
const cameraOffset = new THREE.Vector3(
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
|
479 |
this.camera.position.copy(tankPos).sub(cameraOffset);
|
480 |
this.camera.lookAt(tankPos);
|
|
|
363 |
}
|
364 |
|
365 |
// ์นด๋ฉ๋ผ ์ค์ ์์
|
366 |
+
this.camera.position.set(0, 15, -30); // ์ ์ฐจ ํ๋ฐฉ ์๋จ์ ์์น
|
367 |
+
this.camera.lookAt(new THREE.Vector3(0, 0, 0));
|
368 |
|
369 |
// ๋ก๋ฉ ์๋ฃ
|
370 |
this.isLoading = false;
|
|
|
442 |
if (this.keys.left) direction.x -= 1;
|
443 |
if (this.keys.right) direction.x += 1;
|
444 |
|
445 |
+
// ์์ ๋ณ๊ฒฝ
|
446 |
if (direction.length() > 0) {
|
447 |
direction.normalize();
|
448 |
+
|
449 |
+
// A,D ํค๋ก ํฑํฌ ํ์
|
450 |
+
if (this.keys.left) this.tank.rotate(-1);
|
451 |
+
if (this.keys.right) this.tank.rotate(1);
|
452 |
+
|
453 |
+
// ํ์ฌ ํฑํฌ์ ๋ฐฉํฅ์ผ๋ก ์ด๋
|
454 |
direction.applyEuler(this.tank.body.rotation);
|
455 |
this.tank.move(direction);
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
}
|
457 |
|
458 |
// ๋ง์ฐ์ค ์์น๋ฅผ ํฑํฌ ๊ธฐ์ค์ผ๋ก ๋ณํ
|
|
|
459 |
const mouseVector = new THREE.Vector2(this.mouse.x, -this.mouse.y);
|
460 |
+
const rotationAngle = Math.atan2(mouseVector.x, mouseVector.y);
|
461 |
|
462 |
// ํฌํ ํ์
|
463 |
if (this.tank.turretGroup) {
|
|
|
470 |
const cameraHeight = 10;
|
471 |
|
472 |
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ
|
473 |
+
const tankRotation = this.tank.body.rotation.y;
|
474 |
const cameraOffset = new THREE.Vector3(
|
475 |
+
Math.sin(tankRotation) * cameraDistance,
|
476 |
+
cameraHeight,
|
477 |
+
Math.cos(tankRotation) * cameraDistance
|
478 |
+
);
|
479 |
|
480 |
this.camera.position.copy(tankPos).sub(cameraOffset);
|
481 |
this.camera.lookAt(tankPos);
|