fix(enemy): Approach 逼近改用 aggro/视野双刷新的 LastKnown(修 aggro 先命中扑向错误点)+补 Attack 退出测试

This commit is contained in:
2026-07-24 12:47:48 +08:00
parent f77ab71555
commit 022e4f18d2
3 changed files with 35 additions and 9 deletions
@@ -26,15 +26,14 @@ namespace BaseGames.Enemies
/// <summary>每帧由 EnemyAiBrain 在 Tick 之前调用,维护最后已知位置与丢失计时(供需要的敌人用)。</summary>
public void Refresh(float dt)
{
if (InVisionZone() && _enemy.PlayerTransform != null)
{
bool vision = InVisionZone();
// 追逐区(aggro)或视野内都刷新最后已知位置:Approach 逼近态仅由 aggro 门控进入,
// 若只在视野时刷新,aggro 先于视野命中时 Pursue 会拿到 zero/过期点而扑向错误位置。
if ((vision || InChaseZone()) && _enemy.PlayerTransform != null)
_lastKnown = _enemy.PlayerTransform.position;
_lostTimer = 0f;
}
else
{
_lostTimer += dt;
}
// 丢失计时仍以视野为准(LostFor 语义=脱离视野的时长,不受 aggro 影响)。
if (vision) _lostTimer = 0f;
else _lostTimer += dt;
}
/// <summary>对象池复用时清空临时态。</summary>
@@ -53,7 +53,7 @@ namespace BaseGames.Enemies.Abilities
var c = _candidates[i];
if (Eligible(c, hasLOS, grounded)) total += Mathf.Max(0f, c.Weight);
}
if (total <= 0f) return SelectByPriority(hasLOS, grounded); // 权重全 0 → 退化为确定性取首个合格
if (total <= 0f) return SelectByPriority(hasLOS, grounded); // 权重全 0 → 退化为按 Priority 选(并列取首个)
float roll = Random.value * total;
for (int i = 0; i < _candidates.Count; i++)
{