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