refactor(nav): 敌人移动改为物理原生架构——根治 TBM 与 Dynamic 刚体冲突
根因: NavAgent.Position setter 直接写 transform.position, TBM 段移动每帧写它, 与敌人 Dynamic 刚体(重力/碰撞)冲突(旧代码靠"NavDriving清零velocity"缓解,但对Dynamic刚体直接 写transform.position本就不推荐,易卡墙/穿透/被物理覆盖)。 根本解: 寻路降为"顾问"(只给方向),移动执行归物理: - EnemyNavAgent.Awake 禁用 TBM.SegmentMovement(不再写 transform.position); - FixedUpdate 改物理原生桥: 朝 PathSubGoal 写 MoveDir+MoveSpeed 由 EnemyMovement 施加 velocity+重力执行, 到达子目标时 CompleteSegmentTraversal 推进段(原由TBM负责); - EnemyMovement 撤掉 NavDriving 的清零velocity/只朝向门, nav方向统一走velocity移动。 保留击退/击飞/落地等全部物理反馈。 附带修 PerceptionStateMachine: 追击维持改"追逐区 OR 视野区"任一(视野los可能被墙挡漏检, 仅靠视野会导致玩家在近身追逐区内却Chase↔Patrol抖动、nav被反复Stop不移动)。 PlayMode 验证: 敌人 nav 巡逻/追击均用velocity移动(FollowPath/onSeg=True)、追击稳定无抖动。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -306,10 +306,7 @@ namespace BaseGames.Enemies
|
||||
if (!_isTurning)
|
||||
_facingDir = transform.localScale.x >= 0f ? _spriteDefaultFacingDir : -_spriteDefaultFacingDir;
|
||||
|
||||
// NavDriving: TBM 直接写 transform.position,零速防止物理重力积累和双重驱动冲突。
|
||||
if (NavDriving)
|
||||
_rb.velocity = Vector2.zero;
|
||||
|
||||
// 物理原生移动:nav 只提供方向,移动由 velocity+重力执行(不再让 TBM 写 transform.position)。
|
||||
IsGrounded = IsGroundedCheck();
|
||||
WallAndLedgeCheck();
|
||||
#if UNITY_EDITOR
|
||||
@@ -379,7 +376,6 @@ namespace BaseGames.Enemies
|
||||
{
|
||||
if (_isTurning) return;
|
||||
UpdateFacing(dir);
|
||||
if (NavDriving) return; // TBM 驱动位置,仅更新朝向
|
||||
var vel = _rb.velocity;
|
||||
vel.x = dir * _config.WalkSpeed;
|
||||
_rb.velocity = vel;
|
||||
@@ -390,7 +386,6 @@ namespace BaseGames.Enemies
|
||||
{
|
||||
if (_isTurning) return;
|
||||
UpdateFacing(dir);
|
||||
if (NavDriving) return; // TBM 驱动位置,仅更新朝向
|
||||
var vel = _rb.velocity;
|
||||
vel.x = dir * speed;
|
||||
_rb.velocity = vel;
|
||||
|
||||
Reference in New Issue
Block a user