Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -795,43 +795,76 @@ class EnemyFighter {
|
|
795 |
}
|
796 |
|
797 |
update(playerPosition, deltaTime) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
798 |
|
799 |
avoidOtherEnemies(deltaTime) {
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|