refactor(enemy): 三处卡死检测收敛为 StallDetector;修复 Pace 持续受阻时无法掉头的死锁
This commit is contained in:
@@ -31,9 +31,8 @@ namespace BaseGames.Enemies.Abilities
|
||||
{
|
||||
private RushAbilitySO _cfg;
|
||||
|
||||
// 卡死检测:窗口时长与窗口内最小净位移(撞上未纳入墙层的碰撞体时兜底结束冲锋)
|
||||
private const float StuckWindowSeconds = 0.15f;
|
||||
private const float StuckMinProgress = 0.05f;
|
||||
// 推进停滞检测(撞上未纳入墙层的碰撞体时兜底结束冲锋)
|
||||
private StallDetector _stall = new StallDetector(0.15f, 0.05f);
|
||||
|
||||
// 落位收敛的最长额外推进时长(秒):用于脱离"中心悬在崖外"的非法收尾姿态
|
||||
private const float SettleMaxSeconds = 0.5f;
|
||||
@@ -101,8 +100,7 @@ namespace BaseGames.Enemies.Abilities
|
||||
{
|
||||
var body = _enemy.Body;
|
||||
float elapsed = 0f;
|
||||
float winX = _enemy.transform.position.x;
|
||||
float winT = 0f;
|
||||
_stall.Reset(_enemy.transform.position.x);
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -120,16 +118,8 @@ namespace BaseGames.Enemies.Abilities
|
||||
|
||||
float dt = Time.deltaTime;
|
||||
elapsed += dt;
|
||||
winT += dt;
|
||||
|
||||
// 兜底:撞上未纳入墙层的碰撞体(玩家/边界墙)导致原地不动 → 结束本次冲锋。
|
||||
// 用窗口净位移判定,避免"贴住微抖"每帧重置。
|
||||
if (winT >= StuckWindowSeconds)
|
||||
{
|
||||
if (Mathf.Abs(_enemy.transform.position.x - winX) < StuckMinProgress) break;
|
||||
winX = _enemy.transform.position.x;
|
||||
winT = 0f;
|
||||
}
|
||||
// 兜底:撞上未纳入墙层的碰撞体(玩家/边界墙)导致原地不动 → 结束本次冲锋
|
||||
if (_stall.Tick(_enemy.transform.position.x, dt)) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user