feat(enemy): 目标点吸附统一处理导航宽度,Waypoint 不再卡崖边
将"角色导航宽度"收口到导航执行层单一入口,意图层(Locomotion/AI)只递原始目标、不再感知身体尺寸: - NavAgent 新增 TryGetStandablePointNear:把世界点映射到最近可行走段并按 endMargin 内缩两端(与 SetRandomDestinationOnCurrentSegment 同源) - EnemyNavAgent 新增 ResolveStandablePoint,以 EnemyMovement.EdgeSafeMargin(半宽+落崖余量)为唯一宽度真源;加 _goalMapSearchRadius - IPathAgent 暴露 ResolveStandablePoint;FlyingDirectNavigator 原样返回(飞行无崖沿约束),NullPathAgent 空实现 - EnemyLocomotion Waypoint 分支改用吸附后的可达点做移动与到达判定,修复路点摆在空中/崖外时永不到达而卡死;吸附失败显式报错暴露误配,不静默兜底 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,10 @@ namespace BaseGames.Enemies.Navigation
|
||||
[Tooltip("两次重算最小间隔(s):留出跨帧路径计算完成的时间")]
|
||||
[SerializeField] private float _repathMinInterval = 0.25f;
|
||||
|
||||
[Header("目标点吸附")]
|
||||
[Tooltip("把巡逻/移动目标映射到最近可行走段时允许的最大偏离(m);超出视为无效目标(路点摆得离导航面太远)")]
|
||||
[SerializeField] private float _goalMapSearchRadius = 2f;
|
||||
|
||||
// 重寻路防抖状态
|
||||
private Vector2 _lastPathGoal;
|
||||
private bool _hasPathGoal;
|
||||
@@ -176,6 +180,16 @@ namespace BaseGames.Enemies.Navigation
|
||||
=> _navAgent?.SetRandomDestinationOnCurrentSegment(
|
||||
_enemyMovement != null ? _enemyMovement.EdgeSafeMargin : 0f) ?? false;
|
||||
|
||||
// 目标点吸附:把任意世界目标映射到最近可行走段、并按身体宽度(EdgeSafeMargin)从段两端内缩,
|
||||
// 得到"身体真正站得住"的点。身体宽度是本执行层独占的知识——意图层(AI/Locomotion)只递原始目标。
|
||||
// 映射不到任何段(目标离导航面太远)时返回 false,standable 回落为原始 target。
|
||||
public bool ResolveStandablePoint(Vector2 target, out Vector2 standable)
|
||||
{
|
||||
if (_navAgent == null) { standable = target; return false; }
|
||||
float margin = _enemyMovement != null ? _enemyMovement.EdgeSafeMargin : 0f;
|
||||
return _navAgent.TryGetStandablePointNear(target, _goalMapSearchRadius, margin, out standable);
|
||||
}
|
||||
|
||||
public bool IsNearEdge()
|
||||
{
|
||||
var origin = (Vector2)transform.position;
|
||||
|
||||
Reference in New Issue
Block a user