cutechicken commited on
Commit
6bacfac
β€’
1 Parent(s): 254f9c3

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +11 -37
game.js CHANGED
@@ -106,23 +106,9 @@ class TankPlayer {
106
  update(mouseX, mouseY, scene) {
107
  if (!this.body || !this.turretGroup) return;
108
 
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
 
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 = movementX * 0.001; // 감도 κ°μ†Œ
504
- this.mouse.y = 0; // Y좕은 μ‚¬μš©ν•˜μ§€ μ•ŠμŒ
 
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 targetAngle = this.tank.turretRotation;
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(newCameraAngle) * cameraDistance;
577
- const cameraZ = tankPos.z + Math.cos(newCameraAngle) * cameraDistance;
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,