cutechicken commited on
Commit
47576da
Β·
verified Β·
1 Parent(s): 6c39306

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +5 -130
game.js CHANGED
@@ -815,10 +815,6 @@ class EnemyFighter {
815
  this.temporaryEvadeMode = false;
816
  this.evadeTimer = 0;
817
 
818
- // 후퇴 μ‹œμŠ€ν…œ
819
- this.isRetreating = false;
820
- this.retreatTargetDistance = 250; // λͺ©ν‘œ 후퇴 거리
821
-
822
  // 좩돌 예츑
823
  this.predictedPosition = new THREE.Vector3();
824
 
@@ -899,25 +895,6 @@ class EnemyFighter {
899
 
900
  const distanceToPlayer = this.position.distanceTo(playerPosition);
901
 
902
- // 100m 이내면 μ¦‰μ‹œ 후퇴 λͺ¨λ“œ ν™œμ„±ν™”
903
- if (distanceToPlayer < 100) {
904
- this.isRetreating = true;
905
- this.aiState = 'retreat';
906
- // 후퇴 μ‹œμž‘ μ‹œ 둜그
907
- console.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);
908
- }
909
-
910
- // 250m 이상 λ–¨μ–΄μ§€λ©΄ 후퇴 λͺ¨λ“œ ν•΄μ œ
911
- if (this.isRetreating && distanceToPlayer >= this.retreatTargetDistance) {
912
- this.isRetreating = false;
913
- console.log(`Enemy retreat complete. Distance: ${distanceToPlayer.toFixed(1)}m`);
914
- }
915
-
916
- // μƒνƒœ κ²°μ • - 후퇴가 μ΅œμš°μ„ 
917
- if (this.isRetreating) {
918
- this.aiState = 'retreat';
919
- // 후퇴 μ€‘μ—λŠ” λ‹€λ₯Έ μƒνƒœλ‘œ λ³€κ²½ λΆˆκ°€
920
- } else if (this.temporaryEvadeMode) {
921
  this.aiState = 'evade';
922
  } else if (distanceToPlayer <= 3000) {
923
  this.aiState = 'combat';
@@ -925,11 +902,9 @@ class EnemyFighter {
925
  this.aiState = 'patrol';
926
  }
927
 
928
- // 좩돌 νšŒν”Ό 계산 (후퇴 쀑이 아닐 λ•Œλ§Œ)
929
- if (!this.isRetreating) {
930
- this.calculateAvoidance();
931
- this.checkCollisionPrediction(deltaTime);
932
- }
933
 
934
  // AI 행동 μ‹€ν–‰
935
  switch (this.aiState) {
@@ -942,9 +917,6 @@ class EnemyFighter {
942
  case 'evade':
943
  this.executeEmergencyEvade(deltaTime);
944
  break;
945
- case 'retreat':
946
- this.executeRetreat(playerPosition, deltaTime);
947
- break;
948
  }
949
 
950
  // 물리 μ—…λ°μ΄νŠΈ
@@ -954,56 +926,6 @@ class EnemyFighter {
954
  this.updateBullets(deltaTime);
955
  }
956
 
957
- // μƒˆλ‘œμš΄ λ©”μ„œλ“œ: 후퇴 μ‹€ν–‰
958
- executeRetreat(playerPosition, deltaTime) {
959
- // ν”Œλ ˆμ΄μ–΄λ‘œλΆ€ν„° λ©€μ–΄μ§€λŠ” λ°©ν–₯ 계산
960
- const retreatDirection = this.position.clone().sub(playerPosition).normalize();
961
-
962
- // μˆ˜ν‰ λ°©ν–₯ κ°•μ‘° (수직 이동 κ°μ†Œ)
963
- retreatDirection.y *= 0.3;
964
- retreatDirection.normalize();
965
-
966
- // λͺ©ν‘œ μœ„μΉ˜ μ„€μ • (ν˜„μž¬ μœ„μΉ˜μ—μ„œ ν”Œλ ˆμ΄μ–΄ λ°˜λŒ€ λ°©ν–₯으둜 500m)
967
- const targetPosition = this.position.clone().add(retreatDirection.multiplyScalar(500));
968
-
969
- // 후퇴 μ€‘μ—λŠ” μ΅œλŒ€ 속도
970
- this.speed = this.maxSpeed;
971
-
972
- // 맀우 λΉ λ₯Έ νšŒμ „μœΌλ‘œ μ¦‰μ‹œ 후퇴 λ°©ν–₯을 ν–₯ν•˜λ„λ‘
973
- const targetYaw = Math.atan2(retreatDirection.x, retreatDirection.z);
974
- const targetPitch = Math.asin(-retreatDirection.y);
975
-
976
- // κΈ΄κΈ‰ νšŒμ „ 속도 (3λ°° λΉ λ₯΄κ²Œ)
977
- const emergencyTurnSpeed = this.turnSpeed * 3.0;
978
- const maxTurnRate = emergencyTurnSpeed * deltaTime;
979
-
980
- // Yaw νšŒμ „ (μ¦‰μ‹œ νšŒμ „)
981
- const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
982
- if (Math.abs(yawDiff) > maxTurnRate) {
983
- this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
984
- } else {
985
- this.rotation.y = targetYaw;
986
- }
987
-
988
- // Pitch νšŒμ „ (μ œν•œμ μ΄μ§€λ§Œ λΉ λ₯΄κ²Œ)
989
- const pitchDiff = targetPitch - this.rotation.x;
990
- if (Math.abs(pitchDiff) > maxTurnRate * 0.7) {
991
- this.rotation.x += Math.sign(pitchDiff) * maxTurnRate * 0.7;
992
- } else {
993
- this.rotation.x = targetPitch;
994
- }
995
-
996
- // 후퇴 쀑 κΈ‰μ„ νšŒλ₯Ό μœ„ν•œ λ‘€
997
- this.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 4);
998
-
999
- // 후퇴 μ€‘μ—λŠ” λ°œμ‚¬ κΈˆμ§€
1000
- this.canShoot = false;
1001
- this.burstCounter = 0;
1002
-
1003
- // 좩돌 νšŒν”Ό 벑터 μ΄ˆκΈ°ν™” (후퇴가 μš°μ„ )
1004
- this.avoidanceVector.set(0, 0, 0);
1005
- }
1006
-
1007
  executePatrol(deltaTime) {
1008
  // λͺ©ν‘œ μ§€μ κΉŒμ§€μ˜ 거리 확인
1009
  if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
@@ -1023,13 +945,6 @@ class EnemyFighter {
1023
  executeCombat(playerPosition, deltaTime) {
1024
  const distance = this.position.distanceTo(playerPosition);
1025
 
1026
- // 100m 미만이면 μ¦‰μ‹œ ν›„ν‡΄λ‘œ μ „ν™˜ (이쀑 체크)
1027
- if (distance < 100) {
1028
- this.isRetreating = true;
1029
- this.aiState = 'retreat';
1030
- console.log(`Combat -> Retreat triggered! Distance: ${distance.toFixed(1)}m`);
1031
- return; // μ¦‰μ‹œ λ¦¬ν„΄ν•˜μ—¬ μ „νˆ¬ 둜직 μ‹€ν–‰ λ°©μ§€
1032
- }
1033
 
1034
  // ν”Œλ ˆμ΄μ–΄λ₯Ό ν–₯ν•΄ νšŒμ „
1035
  this.smoothTurnToTarget(playerPosition, deltaTime);
@@ -1043,8 +958,7 @@ class EnemyFighter {
1043
  const isStraightFlying = isPitchLevel && isRollLevel;
1044
 
1045
  // 직진 λΉ„ν–‰ 쀑이고 μ •ν™•ν•œ μ‘°μ€€ μ‹œμ—λ§Œ λ°œμ‚¬ κ°€λŠ₯
1046
- // 200m μ΄μƒμ—μ„œλ§Œ λ°œμ‚¬ (μ•ˆμ „ 거리 확보)
1047
- this.canShoot = isStraightFlying && aimAccuracy < 0.15 && distance > 200;
1048
 
1049
  // λ°œμ‚¬ 쑰건 μΆ©μ‘± μ‹œ λ°œμ‚¬
1050
  if (this.canShoot) {
@@ -1148,46 +1062,7 @@ class EnemyFighter {
1148
  }
1149
 
1150
  smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
1151
- // 후퇴 쀑이면 νšŒν”Ό 벑터 λ¬΄μ‹œ
1152
- if (this.isRetreating) {
1153
- // νƒ€κ²Ÿ λ°©ν–₯ 계산
1154
- const direction = targetPos.clone().sub(this.position);
1155
- direction.y *= 0.5;
1156
- direction.normalize();
1157
-
1158
- // λͺ©ν‘œ νšŒμ „ 계산
1159
- const targetYaw = Math.atan2(direction.x, direction.z);
1160
- const targetPitch = Math.asin(-direction.y);
1161
-
1162
- // 후퇴 μ€‘μ—λŠ” 맀우 λΉ λ₯Έ νšŒμ „
1163
- const turnSpeed = this.turnSpeed * 3.0;
1164
- const maxTurnRate = turnSpeed * deltaTime;
1165
-
1166
- // Yaw νšŒμ „
1167
- const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
1168
- if (Math.abs(yawDiff) > maxTurnRate) {
1169
- this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
1170
- } else {
1171
- this.rotation.y = targetYaw;
1172
- }
1173
-
1174
- // Pitch νšŒμ „
1175
- const maxPitchRate = maxTurnRate * 0.7;
1176
- if (Math.abs(targetPitch - this.rotation.x) > maxPitchRate) {
1177
- this.rotation.x += Math.sign(targetPitch - this.rotation.x) * maxPitchRate;
1178
- } else {
1179
- this.rotation.x = targetPitch;
1180
- }
1181
-
1182
- // Pitch μ œν•œ
1183
- const maxPitchAngle = Math.PI * 40 / 180;
1184
- this.rotation.x = THREE.MathUtils.clamp(this.rotation.x, -maxPitchAngle, maxPitchAngle);
1185
-
1186
- // 후퇴 쀑 κΈ‰μ„ νšŒλ₯Ό μœ„ν•œ λ‘€
1187
- this.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 3);
1188
-
1189
- return; // 후퇴 쀑이면 μ—¬κΈ°μ„œ μ’…λ£Œ
1190
- }
1191
 
1192
  // κΈ°μ‘΄ 둜직 (후퇴가 아닐 λ•Œ)
1193
  const direction = targetPos.clone().sub(this.position);
 
815
  this.temporaryEvadeMode = false;
816
  this.evadeTimer = 0;
817
 
 
 
 
 
818
  // 좩돌 예츑
819
  this.predictedPosition = new THREE.Vector3();
820
 
 
895
 
896
  const distanceToPlayer = this.position.distanceTo(playerPosition);
897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
898
  this.aiState = 'evade';
899
  } else if (distanceToPlayer <= 3000) {
900
  this.aiState = 'combat';
 
902
  this.aiState = 'patrol';
903
  }
904
 
905
+ // 좩돌 νšŒν”Ό 계산
906
+ this.calculateAvoidance();
907
+ this.checkCollisionPrediction(deltaTime);
 
 
908
 
909
  // AI 행동 μ‹€ν–‰
910
  switch (this.aiState) {
 
917
  case 'evade':
918
  this.executeEmergencyEvade(deltaTime);
919
  break;
 
 
 
920
  }
921
 
922
  // 물리 μ—…λ°μ΄νŠΈ
 
926
  this.updateBullets(deltaTime);
927
  }
928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
929
  executePatrol(deltaTime) {
930
  // λͺ©ν‘œ μ§€μ κΉŒμ§€μ˜ 거리 확인
931
  if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
 
945
  executeCombat(playerPosition, deltaTime) {
946
  const distance = this.position.distanceTo(playerPosition);
947
 
 
 
 
 
 
 
 
948
 
949
  // ν”Œλ ˆμ΄μ–΄λ₯Ό ν–₯ν•΄ νšŒμ „
950
  this.smoothTurnToTarget(playerPosition, deltaTime);
 
958
  const isStraightFlying = isPitchLevel && isRollLevel;
959
 
960
  // 직진 λΉ„ν–‰ 쀑이고 μ •ν™•ν•œ μ‘°μ€€ μ‹œμ—λ§Œ λ°œμ‚¬ κ°€λŠ₯
961
+ this.canShoot = isStraightFlying && aimAccuracy < 0.15;
 
962
 
963
  // λ°œμ‚¬ 쑰건 μΆ©μ‘± μ‹œ λ°œμ‚¬
964
  if (this.canShoot) {
 
1062
  }
1063
 
1064
  smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
1065
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
 
1067
  // κΈ°μ‘΄ 둜직 (후퇴가 아닐 λ•Œ)
1068
  const direction = targetPos.clone().sub(this.position);