diff --git a/Assets/Scripts/EnemyAIController.cs b/Assets/Scripts/EnemyAIController.cs index 6c4ba8b..13e1b04 100644 --- a/Assets/Scripts/EnemyAIController.cs +++ b/Assets/Scripts/EnemyAIController.cs @@ -69,7 +69,6 @@ namespace Northbound private Vector3 _chaseStartPosition; private float _lastAttackTime; private bool _hasSetCoreDestination; - private float _lastDetectionLogTime; private bool _isRecalculatingPath = false; // NavMesh 갱신 대기 플래그 private NetworkVariable _currentState = new NetworkVariable( @@ -105,10 +104,6 @@ namespace Northbound _agent.updateRotation = true; _agent.updateUpAxis = false; - if (!_agent.isOnNavMesh) - { - } - if (aiType == TeamType.Monster) { FindCore(); @@ -218,7 +213,11 @@ namespace Northbound private void UpdateChasePlayer() { GameObject targetPlayer = GetTargetPlayer(); - if (targetPlayer == null) { OnLostTarget(); return; } + if (targetPlayer == null) + { + OnLostTarget(); + return; + } float distanceToPlayer = Vector3.Distance(transform.position, targetPlayer.transform.position); Vector3 chaseReferencePoint = (aiType == TeamType.Monster) ? _chaseStartPosition : _originPosition; @@ -282,13 +281,8 @@ namespace Northbound private void UpdateReturnToOrigin() { - GameObject target = DetectTarget(); - if (target != null) - { - SetTargetPlayer(target); - TransitionToState(EnemyAIState.ChasePlayer); - return; - } + // 복귀 중에는 플레이어 감지하지 않음 (무한 루프 방지) + // Idle 상태에 도달하면 다시 감지 시작 if (!_agent.pathPending && _agent.remainingDistance <= _agent.stoppingDistance) { @@ -471,12 +465,23 @@ namespace Northbound _agent.ResetPath(); break; case EnemyAIState.MoveToCore: + _agent.isStopped = false; + _agent.speed = moveSpeed; + if (_coreTransform != null) + { + _agent.SetDestination(_coreTransform.position); + _hasSetCoreDestination = true; + } + break; case EnemyAIState.ChasePlayer: + _agent.isStopped = false; + _agent.speed = moveSpeed * chaseSpeedMultiplier; + _chaseStartPosition = transform.position; + break; case EnemyAIState.ReturnToOrigin: _agent.isStopped = false; - _agent.speed = (state == EnemyAIState.ChasePlayer) ? moveSpeed * chaseSpeedMultiplier : moveSpeed; - if (state == EnemyAIState.ChasePlayer) _chaseStartPosition = transform.position; - if (state == EnemyAIState.ReturnToOrigin) _agent.SetDestination(_originPosition); + _agent.speed = moveSpeed; + _agent.SetDestination(_originPosition); break; case EnemyAIState.Dead: _agent.isStopped = true; @@ -524,8 +529,16 @@ namespace Northbound _isRecalculatingPath = false; - // 코어로 다시 이동 상태 전환 - TransitionToState(aiType == TeamType.Monster ? EnemyAIState.MoveToCore : EnemyAIState.Idle); + // 타입에 따라 적절한 상태로 전환 + // Monster: 코어로 이동, Hostile: 원래 위치로 복귀 + if (aiType == TeamType.Monster) + { + TransitionToState(EnemyAIState.MoveToCore); + } + else + { + TransitionToState(EnemyAIState.ReturnToOrigin); + } } private void FindCore()