cutechicken commited on
Commit
1aa52d5
ยท
verified ยท
1 Parent(s): 6307156

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +65 -32
game.js CHANGED
@@ -795,43 +795,76 @@ class EnemyFighter {
795
  }
796
 
797
  update(playerPosition, deltaTime) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
  avoidOtherEnemies(deltaTime) {
800
- if (!this.nearbyEnemies) return;
801
-
802
- let closestDistance = Infinity;
803
- let avoidanceNeeded = false;
804
- let avoidDirection = new THREE.Vector3();
805
-
806
- this.nearbyEnemies.forEach(enemy => {
807
- if (enemy === this || !enemy.position) return;
808
-
809
- const distance = this.position.distanceTo(enemy.position);
810
- if (distance < this.separationRadius && distance > 0) {
811
- avoidanceNeeded = true;
812
- if (distance < closestDistance) {
813
- closestDistance = distance;
814
- // ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ ํšŒํ”ผ
815
- avoidDirection = this.position.clone().sub(enemy.position).normalize();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
816
  }
817
- }
818
- });
819
-
820
- if (avoidanceNeeded) {
821
- // ๊ธด๊ธ‰ ํšŒํ”ผ: ๊ธ‰์„ ํšŒ
822
- const avoidAngle = Math.atan2(avoidDirection.x, avoidDirection.z);
823
- this.targetRotation.y = avoidAngle;
824
- this.isTurning = true;
825
-
826
- // ๊ณ ๋„๋„ ๋ณ€๊ฒฝ (๋” ๋ถ€๋“œ๋Ÿฝ๊ฒŒ)
827
- if (avoidDirection.y > 0) {
828
- this.targetRotation.x = -0.15; // ๊ธฐ์กด -0.3 โ†’ -0.15 (50% ๊ฐ์†Œ)
829
- } else {
830
- this.targetRotation.x = 0.15; // ๊ธฐ์กด 0.3 โ†’ 0.15 (50% ๊ฐ์†Œ)
831
  }
832
  }
833
- }
834
-
835
  shoot() {
836
  this.lastShootTime = Date.now();
837
 
 
795
  }
796
 
797
  update(playerPosition, deltaTime) {
798
+ if (!this.mesh) return;
799
+
800
+ // AI ์ƒํƒœ ์—…๋ฐ์ดํŠธ
801
+ const distanceToPlayer = this.position.distanceTo(playerPosition);
802
+
803
+ // ์ „ํˆฌ ๊ฑฐ๋ฆฌ ์ฒดํฌ (3000m ์ด๋‚ด)
804
+ if (distanceToPlayer < 3000) {
805
+ this.aiState = 'combat';
806
+ this.isEngaged = true;
807
+ this.targetPosition = playerPosition.clone();
808
+ } else if (distanceToPlayer > 5000) {
809
+ this.aiState = 'patrol';
810
+ this.isEngaged = false;
811
+ }
812
+
813
+ // ๋‹ค๋ฅธ ์ ๊ธฐ์™€์˜ ์ถฉ๋Œ ํšŒํ”ผ
814
+ this.avoidOtherEnemies(deltaTime);
815
+
816
+ // AI ํ–‰๋™ ์‹คํ–‰
817
+ switch (this.aiState) {
818
+ case 'patrol':
819
+ this.patrol(deltaTime);
820
+ break;
821
+ case 'combat':
822
+ this.combat(playerPosition, deltaTime);
823
+ break;
824
+ }
825
+
826
+ // ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ
827
+ this.updatePhysics(deltaTime);
828
+
829
+ // ํƒ„ํ™˜ ์—…๋ฐ์ดํŠธ
830
+ this.updateBullets(deltaTime);
831
+ }
832
 
833
  avoidOtherEnemies(deltaTime) {
834
+ if (!this.nearbyEnemies) return;
835
+
836
+ let closestDistance = Infinity;
837
+ let avoidanceNeeded = false;
838
+ let avoidDirection = new THREE.Vector3();
839
+
840
+ this.nearbyEnemies.forEach(enemy => {
841
+ if (enemy === this || !enemy.position) return;
842
+
843
+ const distance = this.position.distanceTo(enemy.position);
844
+ if (distance < this.separationRadius && distance > 0) {
845
+ avoidanceNeeded = true;
846
+ if (distance < closestDistance) {
847
+ closestDistance = distance;
848
+ // ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ ํšŒํ”ผ
849
+ avoidDirection = this.position.clone().sub(enemy.position).normalize();
850
+ }
851
+ }
852
+ });
853
+
854
+ if (avoidanceNeeded) {
855
+ // ๊ธด๊ธ‰ ํšŒํ”ผ: ๊ธ‰์„ ํšŒ
856
+ const avoidAngle = Math.atan2(avoidDirection.x, avoidDirection.z);
857
+ this.targetRotation.y = avoidAngle;
858
+ this.isTurning = true;
859
+
860
+ // ๊ณ ๋„๋„ ๋ณ€๊ฒฝ (๋” ๋ถ€๋“œ๋Ÿฝ๊ฒŒ)
861
+ if (avoidDirection.y > 0) {
862
+ this.targetRotation.x = -0.15; // ๊ธฐ์กด -0.3 โ†’ -0.15 (50% ๊ฐ์†Œ)
863
+ } else {
864
+ this.targetRotation.x = 0.15; // ๊ธฐ์กด 0.3 โ†’ 0.15 (50% ๊ฐ์†Œ)
865
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
  }
867
  }
 
 
868
  shoot() {
869
  this.lastShootTime = Date.now();
870