cutechicken commited on
Commit
68a71f4
โ€ข
1 Parent(s): d50b5f8

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +15 -14
game.js CHANGED
@@ -363,8 +363,8 @@ class Game {
363
  }
364
 
365
  // ์นด๋ฉ”๋ผ ์„ค์ • ์ˆ˜์ •
366
- this.camera.position.set(-20, 10, -20);
367
- this.camera.lookAt(new THREE.Vector3(0, 0, 0));
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) + tankRotation;
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
- Math.sin(rotationAngle) * cameraDistance,
475
- cameraHeight,
476
- Math.cos(rotationAngle) * cameraDistance
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);