From 4808077fc689bf6696910a454f194457bd0e500b Mon Sep 17 00:00:00 2001 From: Joywayer Date: Mon, 27 Jul 2026 13:38:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(enemy):=20ContactChaseAbility=20=E6=94=B9?= =?UTF-8?q?=E9=80=A0=E4=B8=BA=20RushAbility(=E5=86=B2=E9=94=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 起手前锁定玩家 X 与方向(committed),终点改为身体整体越过锁定点(Body.HasPassed) - 终止条件:越过锁定点/撞墙(只判墙)/最大冲刺时长(SO 新增 maxDashDuration)/净位移卡死 - 冲锋期间经 EnemyMoveInput.AllowLedgeCross 放开悬崖夹紧,可冲下崖不悬停边缘 - 类与文件重命名(GUID 保留),脚手架与向导同步更新 --- .../Editor/Character/CharacterWizardWindow.cs | 6 +- .../Editor/Scene/SceneObjectPlacerTool.cs | 8 +- .../Configs/ContactChaseAbilitySO.cs | 19 --- .../Abilities/Configs/RushAbilitySO.cs | 23 +++ ...bilitySO.cs.meta => RushAbilitySO.cs.meta} | 0 .../Enemies/Abilities/ContactChaseAbility.cs | 113 ------------- .../Scripts/Enemies/Abilities/RushAbility.cs | 156 ++++++++++++++++++ ...aseAbility.cs.meta => RushAbility.cs.meta} | 0 Assets/_Game/Scripts/Enemies/EnemyBase.cs | 15 +- .../_Game/Scripts/Enemies/EnemyMoveInput.cs | 8 + Assets/_Game/Scripts/Enemies/EnemyMovement.cs | 13 +- 11 files changed, 215 insertions(+), 146 deletions(-) delete mode 100644 Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs create mode 100644 Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs rename Assets/_Game/Scripts/Enemies/Abilities/Configs/{ContactChaseAbilitySO.cs.meta => RushAbilitySO.cs.meta} (100%) delete mode 100644 Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs create mode 100644 Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs rename Assets/_Game/Scripts/Enemies/Abilities/{ContactChaseAbility.cs.meta => RushAbility.cs.meta} (100%) diff --git a/Assets/_Game/Scripts/Editor/Character/CharacterWizardWindow.cs b/Assets/_Game/Scripts/Editor/Character/CharacterWizardWindow.cs index 77cfdd64..4f269798 100644 --- a/Assets/_Game/Scripts/Editor/Character/CharacterWizardWindow.cs +++ b/Assets/_Game/Scripts/Editor/Character/CharacterWizardWindow.cs @@ -583,8 +583,8 @@ namespace BaseGames.Editor /// 返回指定敌人类型的 (abilityFileName, abilityId, soType) 定义列表。 private static (string ablName, string ablId, System.Type soType)[] GetEnemyAbilityDefs(string enemyId) => enemyId switch { - // Alert/警觉张口已是纯 locomotion 模式(LocomotionMode.Face),非能力;起手张口并入 ContactChaseAbility 的 Skill_Start。 - "E001" => new[] { ("Chase", "e001_chase", typeof(ContactChaseAbilitySO)) }, + // Alert/警觉张口已是纯 locomotion 模式(LocomotionMode.Face),非能力;起手张口并入 RushAbility 的 Skill_Start。 + "E001" => new[] { ("Chase", "e001_chase", typeof(RushAbilitySO)) }, "E002" => new[] { ("CeilingStrike", "e002_ceiling_strike", typeof(CeilingHangStrikeAbilitySO)) }, "E003" => new[] { ("Fall", "e003_fall", typeof(AnimatedCeilingDropAbilitySO)) }, "E004" => new[] { ("Appear", "e004_appear", typeof(AppearAbilitySO)), @@ -595,7 +595,7 @@ namespace BaseGames.Editor "E005" => new[] { ("Bite", "e005_bite", typeof(EnemyAbilitySO)), ("Acid", "e005_acid", typeof(EnemyAbilitySO)) }, "E006" => new[] { ("Leap", "e006_leap", typeof(EnemyAbilitySO)), - ("Chase", "e006_chase", typeof(ContactChaseAbilitySO)) }, + ("Chase", "e006_chase", typeof(RushAbilitySO)) }, _ => System.Array.Empty<(string, string, System.Type)>(), }; diff --git a/Assets/_Game/Scripts/Editor/Scene/SceneObjectPlacerTool.cs b/Assets/_Game/Scripts/Editor/Scene/SceneObjectPlacerTool.cs index 2218f9da..74847710 100644 --- a/Assets/_Game/Scripts/Editor/Scene/SceneObjectPlacerTool.cs +++ b/Assets/_Game/Scripts/Editor/Scene/SceneObjectPlacerTool.cs @@ -456,8 +456,8 @@ namespace BaseGames.Editor // Model A:AI 只决策触发哪个能力(Idle/Patrol/Alert 已改为纯移动意图,由 EnemyLocomotion 执行,无需挂能力组件) Transform abilitiesT = GetOrCreateChild(go.transform, "Abilities"); - Transform chaseT = GetOrCreateChild(abilitiesT, "ContactChaseAbility_Chase"); - ContactChaseAbility chaseAbility = GetOrAddComponent(chaseT.gameObject); + Transform chaseT = GetOrCreateChild(abilitiesT, "RushAbility_Chase"); + RushAbility chaseAbility = GetOrAddComponent(chaseT.gameObject); // SOs — assign first so OnValidate doesn't warn during wiring AssignAsset(enemyBase, "_statsSO", report, false, "ENM_E001_Stats"); @@ -995,8 +995,8 @@ namespace BaseGames.Editor Transform abilitiesT = GetOrCreateChild(go.transform, "Abilities"); Transform leapT = GetOrCreateChild(abilitiesT, "LeapAttackAbility"); LeapAttackAbility leapAbl = GetOrAddComponent(leapT.gameObject); - Transform chaseT = GetOrCreateChild(abilitiesT, "ContactChaseAbility"); - ContactChaseAbility chaseAbl = GetOrAddComponent(chaseT.gameObject); + Transform chaseT = GetOrCreateChild(abilitiesT, "RushAbility"); + RushAbility chaseAbl = GetOrAddComponent(chaseT.gameObject); // SOs — assign first so OnValidate doesn't warn during wiring AssignAsset(enemyBase, "_statsSO", report, false, "ENM_E006_Stats"); diff --git a/Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs b/Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs deleted file mode 100644 index 65f2817c..00000000 --- a/Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Animancer; -using UnityEngine; - -namespace BaseGames.Enemies.Abilities -{ - /// ContactChaseAbility 的配置:起手/循环/收招动画 + 冲刺速度。 - [CreateAssetMenu(menuName = "BaseGames/Enemies/Abilities/Contact Chase Ability", fileName = "ABL_")] - public class ContactChaseAbilitySO : EnemyAbilitySO - { - [Header("动画(起手 / 循环 / 收招)")] - public ClipTransition startClip; // Skill_Start:张口(一次性) - public ClipTransition loopClip; // Skill_Loop:快速爬行追击(循环) - public ClipTransition endClip; // Skill_End:收招(一次性) - - [Header("冲刺")] - [Tooltip("冲刺速度;<=0 时回退用 EnemyStatsSO.RunSpeed(追击速度)")] - public float dashSpeed = 0f; - } -} diff --git a/Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs b/Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs new file mode 100644 index 00000000..fdf0e8da --- /dev/null +++ b/Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs @@ -0,0 +1,23 @@ +using Animancer; +using UnityEngine; + +namespace BaseGames.Enemies.Abilities +{ + /// RushAbility(冲锋)的配置:起手/循环/收招动画 + 冲刺速度与时长上限。 + [CreateAssetMenu(menuName = "BaseGames/Enemies/Abilities/Rush Ability", fileName = "ABL_")] + public class RushAbilitySO : EnemyAbilitySO + { + [Header("动画(起手 / 循环 / 收招)")] + public ClipTransition startClip; // Skill_Start:起手(一次性) + public ClipTransition loopClip; // Skill_Loop:冲锋推进(循环) + public ClipTransition endClip; // Skill_End:收招(一次性) + + [Header("冲刺")] + [Tooltip("冲刺速度;<=0 时回退用 EnemyStatsSO.RunSpeed(追击速度)")] + public float dashSpeed = 0f; + + [Tooltip("单次冲锋的最长时长(秒)。够不到锁定点时(掉坑/对岸/被非检测层挡住)由它收尾。" + + "0 = 不限时长(仅靠越过锁定点/撞墙/卡死检测终止)。")] + [Min(0f)] public float maxDashDuration = 2f; + } +} diff --git a/Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs.meta b/Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs.meta similarity index 100% rename from Assets/_Game/Scripts/Enemies/Abilities/Configs/ContactChaseAbilitySO.cs.meta rename to Assets/_Game/Scripts/Enemies/Abilities/Configs/RushAbilitySO.cs.meta diff --git a/Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs b/Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs deleted file mode 100644 index b919bf69..00000000 --- a/Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System.Collections; -using Animancer; -using UnityEngine; - -namespace BaseGames.Enemies.Abilities -{ - /// - /// 冲刺追击能力:起手(Skill_Start 张口) → 朝玩家方向直冲(Skill_Loop 快速爬行), - /// **直到撞墙/到平台边缘或玩家消失即停** → 收招(Skill_End)。一次冲刺为一次能力执行, - /// 结束后进入冷却(EnemyAbilitySO.cooldown);AI 追击态在冷却结束时经 EnsureAbility 重触发下一次冲刺。 - /// 冲刺方向在起手后按玩家所在侧一次性确定(committed 冲锋,会越过跳开的玩家,可被躲)。 - /// 追击动画由本能力全权驱动(Approach 步态不抢动画)。 - /// 身体接触伤害与本能力解耦:由常驻的 全程负责,本能力不再开关它。 - /// - public class ContactChaseAbility : EnemyAbilityBase - { - private ContactChaseAbilitySO _cfg; - - protected override void Awake() - { - base.Awake(); - _cfg = ResolveConfig(); - } - - protected override IEnumerator ExecuteCoroutine() - { - if (_cfg == null) yield break; - - Phase = AbilityRunState.Active; - _enemy.SetEngaged(true); - - // 冲刺方向:按玩家所在侧一次性确定(committed 冲锋) - float dir = (_enemy.PlayerTransform != null && - _enemy.PlayerTransform.position.x < _enemy.transform.position.x) ? -1f : 1f; - var mv = _enemy.Movement; - - // 先转身朝玩家(背对时播 Flip 转身动画),转身完成后再张口 - if (mv != null) - { - mv.FaceDirection((int)dir); - while (mv.IsTurning) - yield return null; - } - - // 起手:张口(一次性)。期间静止、不伤人;锁住动画防被步态覆盖。 - if (_cfg.startClip.Clip != null) - { - _enemy.LockAnim(_cfg.startClip.Clip.length); - _animancer.Play(_cfg.startClip); - yield return EnemyAbilityWaits.Get(_cfg.startClip.Clip.length); - } - - // 冲刺速度:优先能力配置的 _cfg.dashSpeed,否则回退 Stats.RunSpeed - float speed = _cfg.dashSpeed > 0f ? _cfg.dashSpeed - : (_enemy.Stats != null ? _enemy.Stats.RunSpeed : 0f); - - // 冲刺:朝该方向直冲、播 Skill_Loop,直到撞墙/到边缘或玩家消失即停。 - // (身体接触伤害由常驻 BodyContactDamage 全程负责,此处不再开关。) - if (_cfg.loopClip.Clip != null) - _animancer.Play(_cfg.loopClip); - - float winX = _enemy.transform.position.x; - float winT = 0f; - while (_enemy.PlayerTransform != null && !(mv != null && mv.WouldBlockAhead(dir))) - { - _enemy.MoveInDirectionWithSpeed(dir, speed); // 速度直冲(非 nav),MoveWithSpeed 悬崖夹紧兜底 - yield return null; - - // 兜底:撞上未在检测层的碰撞体(玩家/边界墙)导致原地不动 → 结束本次冲刺(转收招+冷却)。 - // 用窗口净位移判定,避免"贴住微抖"每帧重置。 - winT += Time.deltaTime; - if (winT >= 0.15f) - { - if (Mathf.Abs(_enemy.transform.position.x - winX) < 0.05f) break; - winX = _enemy.transform.position.x; - winT = 0f; - } - } - _enemy.StopMovement(); - - // 收招 Skill_End;随后基类按 EnemyAbilitySO.cooldown 施加冷却。 - yield return PlaySkillEnd(); - Cleanup(); - } - - protected override void OnInterrupted(InterruptReason reason) - { - // 丢失目标 = AI 主动退出追击态(ExternalRequest) → 播收招 Skill_End; - // 受击/死亡/硬直等硬打断不播收招。协程已停,fire-and-forget;动画锁保证 Skill_End - // 在其时长内不被巡逻步态盖掉。 - if (reason == InterruptReason.ExternalRequest && _cfg != null && _cfg.endClip.Clip != null) - { - _enemy.LockAnim(_cfg.endClip.Clip.length); - _animancer.Play(_cfg.endClip); - } - Cleanup(); - } - - private IEnumerator PlaySkillEnd() - { - if (_cfg == null || _cfg.endClip.Clip == null) yield break; - _enemy.LockAnim(_cfg.endClip.Clip.length); - _animancer.Play(_cfg.endClip); - yield return EnemyAbilityWaits.Get(_cfg.endClip.Clip.length); - } - - private void Cleanup() - { - _enemy.SetEngaged(false); - _enemy.Locomotion?.Stop(); - } - } -} diff --git a/Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs b/Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs new file mode 100644 index 00000000..814bc0d3 --- /dev/null +++ b/Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs @@ -0,0 +1,156 @@ +using System.Collections; +using Animancer; +using UnityEngine; + +namespace BaseGames.Enemies.Abilities +{ + /// + /// 冲锋能力:起手(Skill_Start) → 朝**锁定点**直冲(Skill_Loop) → 收招(Skill_End)。 + /// 一次冲锋为一次能力执行,结束后进入冷却(EnemyAbilitySO.cooldown)。 + /// + /// 冲锋目标在**起手动画之前**锁定:记下玩家当时的 X 与由此确定的方向,此后玩家怎么动都不改变本次冲锋 + /// (committed 冲锋——起手即预警,玩家可在起手期间跑开躲掉)。 + /// + /// 终点判据是"**身体整体越过**锁定点"(),即碰撞体后缘越过锁定 X, + /// 而非中心到达——身体宽度取自身体几何权威 ,本能力不自行解析碰撞体。 + /// + /// 终止条件(任一满足即收招并进入冷却):身体整体越过锁定点(正常完成)/前方有墙(只判墙,不判悬崖)/ + /// 超过 (够不到锁定点时收尾:掉坑、对岸、被非检测层挡住)/ + /// 净位移卡死(撞上未纳入墙层的碰撞体时兜底)。 + /// + /// 悬崖:冲锋期间**允许越过崖沿**(经 放开移动层的悬崖夹紧), + /// 敌人会冲出平台边缘并按重力下落、空中保持水平冲速,而不是停在崖边悬空。 + /// + /// 冲锋动画由本能力全权驱动(步态不抢动画)。身体接触伤害与本能力解耦: + /// 由常驻的 全程负责,本能力不开关它。 + /// + public class RushAbility : EnemyAbilityBase + { + private RushAbilitySO _cfg; + + // 卡死检测:窗口时长与窗口内最小净位移(撞上未纳入墙层的碰撞体时兜底结束冲锋) + private const float StuckWindowSeconds = 0.15f; + private const float StuckMinProgress = 0.05f; + + protected override void Awake() + { + base.Awake(); + _cfg = ResolveConfig(); + } + + protected override IEnumerator ExecuteCoroutine() + { + if (_cfg == null) yield break; + + Phase = AbilityRunState.Active; + _enemy.SetEngaged(true); + + // ── 锁定:起手之前记下玩家 X 与方向,此后不再跟随(committed 冲锋,可被躲)── + var player = _enemy.PlayerTransform; + float dir = (player != null && player.position.x < _enemy.transform.position.x) ? -1f : 1f; + float lockX = player != null + ? player.position.x + : _enemy.transform.position.x + dir; // 无玩家:朝当前朝向冲一个身位,仍走完整流程 + + var mv = _enemy.Movement; + + // 先转身朝锁定方向(背对时播转身动画),转身完成后再起手 + if (mv != null) + { + mv.FaceDirection((int)dir); + while (mv.IsTurning) + yield return null; + } + + // 起手:一次性预警动画。期间静止;锁住动画防被步态覆盖。 + if (_cfg.startClip.Clip != null) + { + _enemy.LockAnim(_cfg.startClip.Clip.length); + _animancer.Play(_cfg.startClip); + yield return EnemyAbilityWaits.Get(_cfg.startClip.Clip.length); + } + + // 冲刺速度:优先能力配置的 dashSpeed,否则回退 Stats.RunSpeed + float speed = _cfg.dashSpeed > 0f ? _cfg.dashSpeed + : (_enemy.Stats != null ? _enemy.Stats.RunSpeed : 0f); + + if (_cfg.loopClip.Clip != null) + _animancer.Play(_cfg.loopClip); + + yield return RushRoutine(dir, lockX, speed, mv); + + _enemy.StopMovement(); + + // 收招 Skill_End;随后基类按 EnemyAbilitySO.cooldown 施加冷却。 + yield return PlaySkillEnd(); + Cleanup(); + } + + /// + /// 冲锋推进:每帧朝锁定方向施加冲速(允许越崖), + /// 直到身体整体越过锁定点/撞墙/超时/卡死。 + /// + private IEnumerator RushRoutine(float dir, float lockX, float speed, EnemyMovement mv) + { + var body = _enemy.Body; + float elapsed = 0f; + float winX = _enemy.transform.position.x; + float winT = 0f; + + while (true) + { + // 终点:身体整体越过锁定点(后缘越过;宽度由身体权威提供) + if (body != null && body.HasPassed(lockX, dir)) break; + + // 撞墙即止(悬崖不再终止——冲锋要能冲下去) + if (mv != null && mv.WouldHitWallAhead(dir)) break; + + // 超时收尾:够不到锁定点(掉坑/对岸/被非检测层挡住) + if (_cfg.maxDashDuration > 0f && elapsed >= _cfg.maxDashDuration) break; + + _enemy.MoveInDirectionWithSpeed(dir, speed, allowLedgeCross: true); + yield return null; + + 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; + } + } + } + + protected override void OnInterrupted(InterruptReason reason) + { + // 丢失目标 = AI 主动退出(ExternalRequest) → 播收招 Skill_End; + // 受击/死亡/硬直等硬打断不播收招。协程已停,fire-and-forget;动画锁保证 Skill_End + // 在其时长内不被巡逻步态盖掉。 + if (reason == InterruptReason.ExternalRequest && _cfg != null && _cfg.endClip.Clip != null) + { + _enemy.LockAnim(_cfg.endClip.Clip.length); + _animancer.Play(_cfg.endClip); + } + Cleanup(); + } + + private IEnumerator PlaySkillEnd() + { + if (_cfg == null || _cfg.endClip.Clip == null) yield break; + _enemy.LockAnim(_cfg.endClip.Clip.length); + _animancer.Play(_cfg.endClip); + yield return EnemyAbilityWaits.Get(_cfg.endClip.Clip.length); + } + + private void Cleanup() + { + _enemy.SetEngaged(false); + _enemy.Locomotion?.Stop(); // 经 StopMovement 路径一并复位 AllowLedgeCross + } + } +} diff --git a/Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs.meta b/Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs.meta similarity index 100% rename from Assets/_Game/Scripts/Enemies/Abilities/ContactChaseAbility.cs.meta rename to Assets/_Game/Scripts/Enemies/Abilities/RushAbility.cs.meta diff --git a/Assets/_Game/Scripts/Enemies/EnemyBase.cs b/Assets/_Game/Scripts/Enemies/EnemyBase.cs index e0470ed8..0e5cc359 100644 --- a/Assets/_Game/Scripts/Enemies/EnemyBase.cs +++ b/Assets/_Game/Scripts/Enemies/EnemyBase.cs @@ -266,11 +266,20 @@ namespace BaseGames.Enemies } public virtual void MoveInDirectionWithSpeed(float dir, float speed) + => MoveInDirectionWithSpeed(dir, speed, false); + + /// + /// 显式速度移动; = true 时允许冲出崖沿并自由落体 + /// (committed 冲锋用,避免被移动层的悬崖夹紧停在边缘)。 + /// 该许可随移动意图存续,StopMovement() 时自动复位。 + /// + public virtual void MoveInDirectionWithSpeed(float dir, float speed, bool allowLedgeCross) { if (_movement == null) return; - _movement.PendingInput.MoveDir = dir; - _movement.PendingInput.MoveSpeed = speed; - _movement.PendingInput.WantStop = false; // 移动意图覆盖停止脉冲 + _movement.PendingInput.MoveDir = dir; + _movement.PendingInput.MoveSpeed = speed; + _movement.PendingInput.AllowLedgeCross = allowLedgeCross; + _movement.PendingInput.WantStop = false; // 移动意图覆盖停止脉冲 } public virtual void StopMovement() diff --git a/Assets/_Game/Scripts/Enemies/EnemyMoveInput.cs b/Assets/_Game/Scripts/Enemies/EnemyMoveInput.cs index 6d77c211..9a54775a 100644 --- a/Assets/_Game/Scripts/Enemies/EnemyMoveInput.cs +++ b/Assets/_Game/Scripts/Enemies/EnemyMoveInput.cs @@ -34,5 +34,13 @@ namespace BaseGames.Enemies /// 直接指定朝向方向:+1 右 / -1 左 / 0 表示由 FaceTargetPos 计算。 public int FaceDir; + + /// + /// 本次移动允许越过崖沿(committed 冲锋用):置 true 时 + /// 不再做悬崖夹紧,敌人会冲出平台边缘并按重力下落,而非停在崖边。 + /// 持久——随 MoveDir/MoveSpeed 同步清零(WantStop 时复位),故 StopMovement() 即自动关闭, + /// 不会因能力被打断而残留。 + /// + public bool AllowLedgeCross; } } diff --git a/Assets/_Game/Scripts/Enemies/EnemyMovement.cs b/Assets/_Game/Scripts/Enemies/EnemyMovement.cs index 87a9ad47..85b55bed 100644 --- a/Assets/_Game/Scripts/Enemies/EnemyMovement.cs +++ b/Assets/_Game/Scripts/Enemies/EnemyMovement.cs @@ -404,12 +404,13 @@ namespace BaseGames.Enemies { PendingInput.MoveDir = 0f; PendingInput.MoveSpeed = 0f; + PendingInput.AllowLedgeCross = false; // 随移动意图一并复位,避免越崖许可残留 StopHorizontal(); } else if (PendingInput.MoveDir != 0f) { if (PendingInput.MoveSpeed > 0f) - MoveWithSpeed(PendingInput.MoveDir, PendingInput.MoveSpeed); + MoveWithSpeed(PendingInput.MoveDir, PendingInput.MoveSpeed, PendingInput.AllowLedgeCross); else MoveHorizontal(PendingInput.MoveDir); } @@ -435,15 +436,19 @@ namespace BaseGames.Enemies _rb.velocity = vel; } - /// 显式指定速度(BD 追击任务调用)。转身动画期间调用无效。 - public void MoveWithSpeed(float dir, float speed) + /// + /// 显式指定速度移动。转身动画期间调用无效。 + /// = true 时跳过悬崖夹紧,允许冲出平台边缘后自由落体 + /// (committed 冲锋用;见 )。 + /// + public void MoveWithSpeed(float dir, float speed, bool allowLedgeCross = false) { if (_isTurning) return; if (dir != 0f) UpdateFacing(dir); // 地面怪追击/导航:前缘将越过地形边缘(悬崖)则不前进——碰撞体边缘停在地形边缘、不越界。 // 只夹"悬崖"不夹"墙"(墙交给寻路绕行,免得贴墙路径被误夹停);跨沟的 nav-link 跳/落 // 不经本方法(EnemyNavAgent 仅在 IsMovingOnSegment 时写 MoveSpeed),故不影响跳跃/下落过沟。 - if (dir != 0f && IsGrounded && WouldFallAhead(dir)) dir = 0f; + if (dir != 0f && !allowLedgeCross && IsGrounded && WouldFallAhead(dir)) dir = 0f; var vel = _rb.velocity; vel.x = dir * speed; _rb.velocity = vel;