From 702c0b4f9e40086d0fbaef5b206798df578c9caa Mon Sep 17 00:00:00 2001 From: dal4segno Date: Thu, 19 Feb 2026 01:13:04 +0900 Subject: [PATCH] =?UTF-8?q?creep=EC=9D=98=20=EC=9B=90=EC=A0=90=20=ED=9A=8C?= =?UTF-8?q?=EA=B7=80=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 되돌아가지 않는 문제 수정 되돌아 가는 도중에 플레이어를 다시 인식하는 문제 수정 --- Assets/Scripts/EnemyAIController.cs | 49 ++++++++++++++++++----------- 1 file changed, 31 insertions(+), 18 deletions(-) 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()