Update game.js
Browse files814 unmodified lines81581681781881982082182282382474 unmodified lines8999009019029039049059069079089099109119129139149159169179189199209219229231 unmodified line9259269279289299309319329339349356 unmodified lines9429439449459469479489499503 unmodified lines954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100913 unmodified lines10231024102510261027102810291030103110321033103410357 unmodified lines1043104410451046104710481049105097 unmodified lines1148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193814 unmodified linesthis.temporaryEvadeMode = false;this.evadeTimer = 0;// ํํด ์์คํ this.isRetreating = false;this.retreatTargetDistance = 250; // ๋ชฉํ ํํด ๊ฑฐ๋ฆฌ// ์ถฉ๋ ์์ธกthis.predictedPosition = new THREE.Vector3();74 unmodified linesconst distanceToPlayer = this.position.distanceTo(playerPosition);// 100m ์ด๋ด๋ฉด ์ฆ์ ํํด ๋ชจ๋ ํ์ฑํif (distanceToPlayer < 100) {this.isRetreating = true;this.aiState = 'retreat';// ํํด ์์ ์ ๋ก๊ทธconsole.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);}// 250m ์ด์ ๋จ์ด์ง๋ฉด ํํด ๋ชจ๋ ํด์ if (this.isRetreating && distanceToPlayer >= this.retreatTargetDistance) {this.isRetreating = false;console.log(`Enemy retreat complete. Distance: ${distanceToPlayer.toFixed(1)}m`);}// ์ํ ๊ฒฐ์ - ํํด๊ฐ ์ต์ฐ์if (this.isRetreating) {this.aiState = 'retreat';// ํํด ์ค์๋ ๋ค๋ฅธ ์ํ๋ก ๋ณ๊ฒฝ ๋ถ๊ฐ} else if (this.temporaryEvadeMode) {this.aiState = 'evade';} else if (distanceToPlayer <= 3000) {this.aiState = 'combat';1 unmodified linethis.aiState = 'patrol';}// ์ถฉ๋ ํํผ ๊ณ์ฐ (ํํด ์ค์ด ์๋ ๋๋ง)if (!this.isRetreating) {this.calculateAvoidance();this.checkCollisionPrediction(deltaTime);}// AI ํ๋ ์คํswitch (this.aiState) {6 unmodified linescase 'evade':this.executeEmergencyEvade(deltaTime);break;case 'retreat':this.executeRetreat(playerPosition, deltaTime);break;}// ๋ฌผ๋ฆฌ ์ ๋ฐ์ดํธ3 unmodified linesthis.updateBullets(deltaTime);}// ์๋ก์ด ๋ฉ์๋: ํํด ์คํexecuteRetreat(playerPosition, deltaTime) {// ํ๋ ์ด์ด๋ก๋ถํฐ ๋ฉ์ด์ง๋ ๋ฐฉํฅ ๊ณ์ฐconst retreatDirection = this.position.clone().sub(playerPosition).normalize();// ์ํ ๋ฐฉํฅ ๊ฐ์กฐ (์์ง ์ด๋ ๊ฐ์)retreatDirection.y *= 0.3;retreatDirection.normalize();// ๋ชฉํ ์์น ์ค์ (ํ์ฌ ์์น์์ ํ๋ ์ด์ด ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก 500m)const targetPosition = this.position.clone().add(retreatDirection.multiplyScalar(500));// ํํด ์ค์๋ ์ต๋ ์๋this.speed = this.maxSpeed;// ๋งค์ฐ ๋น ๋ฅธ ํ์ ์ผ๋ก ์ฆ์ ํํด ๋ฐฉํฅ์ ํฅํ๋๋กconst targetYaw = Math.atan2(retreatDirection.x, retreatDirection.z);const targetPitch = Math.asin(-retreatDirection.y);// ๊ธด๊ธ ํ์ ์๋ (3๋ฐฐ ๋น ๋ฅด๊ฒ)const emergencyTurnSpeed = this.turnSpeed * 3.0;const maxTurnRate = emergencyTurnSpeed * deltaTime;// Yaw ํ์ (์ฆ์ ํ์ )const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);if (Math.abs(yawDiff) > maxTurnRate) {this.rotation.y += Math.sign(yawDiff) * maxTurnRate;} else {this.rotation.y = targetYaw;}// Pitch ํ์ (์ ํ์ ์ด์ง๋ง ๋น ๋ฅด๊ฒ)const pitchDiff = targetPitch - this.rotation.x;if (Math.abs(pitchDiff) > maxTurnRate * 0.7) {this.rotation.x += Math.sign(pitchDiff) * maxTurnRate * 0.7;} else {this.rotation.x = targetPitch;}// ํํด ์ค ๊ธ์ ํ๋ฅผ ์ํ ๋กคthis.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 4);// ํํด ์ค์๋ ๋ฐ์ฌ ๊ธ์งthis.canShoot = false;this.burstCounter = 0;// ์ถฉ๋ ํํผ ๋ฒกํฐ ์ด๊ธฐํ (ํํด๊ฐ ์ฐ์ )this.avoidanceVector.set(0, 0, 0);}executePatrol(deltaTime) {// ๋ชฉํ ์ง์ ๊น์ง์ ๊ฑฐ๋ฆฌ ํ์ธif (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {13 unmodified linesexecuteCombat(playerPosition, deltaTime) {const distance = this.position.distanceTo(playerPosition);// 100m ๋ฏธ๋ง์ด๋ฉด ์ฆ์ ํํด๋ก ์ ํ (์ด์ค ์ฒดํฌ)if (distance < 100) {this.isRetreating = true;this.aiState = 'retreat';console.log(`Combat -> Retreat triggered! Distance: ${distance.toFixed(1)}m`);return; // ์ฆ์ ๋ฆฌํดํ์ฌ ์ ํฌ ๋ก์ง ์คํ ๋ฐฉ์ง}// ํ๋ ์ด์ด๋ฅผ ํฅํด ํ์ this.smoothTurnToTarget(playerPosition, deltaTime);7 unmodified linesconst isStraightFlying = isPitchLevel && isRollLevel;// ์ง์ง ๋นํ ์ค์ด๊ณ ์ ํํ ์กฐ์ค ์์๋ง ๋ฐ์ฌ ๊ฐ๋ฅ// 200m ์ด์์์๋ง ๋ฐ์ฌ (์์ ๊ฑฐ๋ฆฌ ํ๋ณด)this.canShoot = isStraightFlying && aimAccuracy < 0.15 && distance > 200;// ๋ฐ์ฌ ์กฐ๊ฑด ์ถฉ์กฑ ์ ๋ฐ์ฌif (this.canShoot) {97 unmodified lines}smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {// ํํด ์ค์ด๋ฉด ํํผ ๋ฒกํฐ ๋ฌด์if (this.isRetreating) {// ํ๊ฒ ๋ฐฉํฅ ๊ณ์ฐconst direction = targetPos.clone().sub(this.position);direction.y *= 0.5;direction.normalize();// ๋ชฉํ ํ์ ๊ณ์ฐconst targetYaw = Math.atan2(direction.x, direction.z);const targetPitch = Math.asin(-direction.y);// ํํด ์ค์๋ ๋งค์ฐ ๋น ๋ฅธ ํ์ const turnSpeed = this.turnSpeed * 3.0;const maxTurnRate = turnSpeed * deltaTime;// Yaw ํ์ const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);if (Math.abs(yawDiff) > maxTurnRate) {this.rotation.y += Math.sign(yawDiff) * maxTurnRate;} else {this.rotation.y = targetYaw;}// Pitch ํ์ const maxPitchRate = maxTurnRate * 0.7;if (Math.abs(targetPitch - this.rotation.x) > maxPitchRate) {this.rotation.x += Math.sign(targetPitch - this.rotation.x) * maxPitchRate;} else {this.rotation.x = targetPitch;}// Pitch ์ ํconst maxPitchAngle = Math.PI * 40 / 180;this.rotation.x = THREE.MathUtils.clamp(this.rotation.x, -maxPitchAngle, maxPitchAngle);// ํํด ์ค ๊ธ์ ํ๋ฅผ ์ํ ๋กคthis.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 3);return; // ํํด ์ค์ด๋ฉด ์ฌ๊ธฐ์ ์ข ๋ฃ}// ๊ธฐ์กด ๋ก์ง (ํํด๊ฐ ์๋ ๋)const direction = targetPos.clone().sub(this.position);814 unmodified lines81581681781881982074 unmodified lines8958968978988999001 unmodified line9029039049059069079089099106 unmodified lines9179189199209219223 unmodified lines92692792892993093113 unmodified lines9459469479489499507 unmodified lines95895996096196296396497 unmodified lines1062106310641065106610671068814 unmodified linesthis.temporaryEvadeMode = false;this.evadeTimer = 0;// ์ถฉ๋ ์์ธกthis.predictedPosition = new THREE.Vector3();74 unmodified linesconst distanceToPlayer = this.position.distanceTo(playerPosition);this.aiState = 'evade';} else if (distanceToPlayer <= 3000) {this.aiState = 'combat';1 unmodified linethis.aiState = 'patrol';}// ์ถฉ๋ ํํผ ๊ณ์ฐthis.calculateAvoidance();this.checkCollisionPrediction(deltaTime);// AI ํ๋ ์คํswitch (this.aiState) {6 unmodified linescase 'evade':this.executeEmergencyEvade(deltaTime);break;}// ๋ฌผ๋ฆฌ ์ ๋ฐ์ดํธ3 unmodified linesthis.updateBullets(deltaTime);}executePatrol(deltaTime) {// ๋ชฉํ ์ง์ ๊น์ง์ ๊ฑฐ๋ฆฌ ํ์ธif (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {13 unmodified linesexecuteCombat(playerPosition, deltaTime) {const distance = this.position.distanceTo(playerPosition);// ํ๋ ์ด์ด๋ฅผ ํฅํด ํ์ this.smoothTurnToTarget(playerPosition, deltaTime);7 unmodified linesconst isStraightFlying = isPitchLevel && isRollLevel;// ์ง์ง ๋นํ ์ค์ด๊ณ ์ ํํ ์กฐ์ค ์์๋ง ๋ฐ์ฌ ๊ฐ๋ฅthis.canShoot = isStraightFlying && aimAccuracy < 0.15;// ๋ฐ์ฌ ์กฐ๊ฑด ์ถฉ์กฑ ์ ๋ฐ์ฌif (this.canShoot) {97 unmodified lines}smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {// ๊ธฐ์กด ๋ก์ง (ํํด๊ฐ ์๋ ๋)const direction = targetPos.clone().sub(this.position);
game.js+5-130