feat : 몬스터 순간이동 구현
- 몬스터가 구석에 몰려 더이상 움직일 수 없는 경우 중앙으로 워프 Work in JIRA ISSUE DEG-100
This commit is contained in:
parent
50e5b8db98
commit
18211fff05
@ -10,7 +10,7 @@ public class CasterDemonController : EnemyController
|
||||
[SerializeField] private Transform teleportTransform;
|
||||
[SerializeField] private Transform bulletShotPosition;
|
||||
[SerializeField] private GameObject magicMissilePrefab;
|
||||
|
||||
[SerializeField] private GameObject teleportEffectPrefab;
|
||||
public override void BattleSequence()
|
||||
{
|
||||
// 전투 행동이 이미 진행 중일 경우 실행 막기
|
||||
@ -22,21 +22,15 @@ public class CasterDemonController : EnemyController
|
||||
// TODO : 배틀 중일 때 루프
|
||||
Debug.Log("## 몬스터의 교전 행동 루프");
|
||||
StartCoroutine(ShotMagicMissile());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OnCannotFleeBehaviour()
|
||||
{
|
||||
if (_isFirstNoPath)
|
||||
{
|
||||
Debug.Log("## 몬스터가 처음으로 막다른 길에 몰렸습니다.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("## 몬스터가 다시 막다른 길에 몰렸습니다.");
|
||||
}
|
||||
// 구석에 끼인 경우 탈출
|
||||
|
||||
Debug.Log("## 텔레포트 시전");
|
||||
Teleport();
|
||||
}
|
||||
|
||||
private IEnumerator ShotMagicMissile()
|
||||
@ -83,7 +77,16 @@ public class CasterDemonController : EnemyController
|
||||
|
||||
private void Teleport()
|
||||
{
|
||||
if (teleportEffectPrefab != null)
|
||||
Instantiate(teleportEffectPrefab, transform.position, Quaternion.identity);
|
||||
|
||||
if (Agent != null && teleportTransform != null)
|
||||
Agent.Warp(teleportTransform.position);
|
||||
else if (teleportTransform != null)
|
||||
transform.position = teleportTransform.position;
|
||||
|
||||
if (teleportEffectPrefab != null && teleportTransform != null)
|
||||
Instantiate(teleportEffectPrefab, teleportTransform.position, Quaternion.identity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class EnemyStateFlee :IEnemyState
|
||||
private Vector3 _lastPosition;
|
||||
private float _stuckTimer = 0f;
|
||||
private const float StuckThresholdTime = 1f; // 1초 동안 거의 못 움직이면 막힌 걸로 간주
|
||||
private const float StuckMoveThreshold = 0.1f; // 이내 이동은 “제자리”로 본다
|
||||
private const float StuckMoveThreshold = 0.01f; // 이내 이동은 “제자리”로 본다
|
||||
|
||||
public void Enter(EnemyController enemyController)
|
||||
{
|
||||
@ -58,7 +58,7 @@ public class EnemyStateFlee :IEnemyState
|
||||
if (!_enemyController.Agent.pathPending &&
|
||||
_enemyController.Agent.pathStatus == NavMeshPathStatus.PathInvalid)
|
||||
{
|
||||
// 막다른 길임 : 대체 행동 실행
|
||||
Debug.Log("## 길을 못찾음");
|
||||
HandleDeadEnd();
|
||||
}
|
||||
|
||||
@ -76,6 +76,8 @@ public class EnemyStateFlee :IEnemyState
|
||||
_stuckTimer += Time.deltaTime;
|
||||
if (_stuckTimer >= StuckThresholdTime)
|
||||
{
|
||||
|
||||
Debug.Log("## 끼임");
|
||||
HandleDeadEnd();
|
||||
_stuckTimer = 0f;
|
||||
}
|
||||
@ -111,14 +113,20 @@ public class EnemyStateFlee :IEnemyState
|
||||
|
||||
if (NavMesh.SamplePosition(randomDirection, out var hit, (_fleeDistance * 2), NavMesh.AllAreas))
|
||||
{
|
||||
// 샘플링에 성공했으면 일단 그 위치로 가 보도록 세팅
|
||||
Debug.Log("## 일단 가봄");
|
||||
_enemyController.Agent.SetDestination(hit.position);
|
||||
return;
|
||||
_enemyController.OnCannotFleeBehaviour();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 대체 경로도 찾을 수 없는 경우
|
||||
Debug.Log("## 대체 경로도 못찾음");
|
||||
_enemyController.OnCannotFleeBehaviour();
|
||||
}
|
||||
|
||||
// 대체 경로도 찾을 수 없는 경우
|
||||
_enemyController.OnCannotFleeBehaviour();
|
||||
}
|
||||
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_enemyController.Agent.isStopped = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user