From 70c827c24f5f7b3fab1fa5c22f672ee819931e95 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 12 May 2026 19:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E8=8B=B1=E9=9B=84=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=B3=BB=E7=BB=9F):=20=E5=AE=8C=E5=96=84=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E5=88=B0=E4=BD=8D=E5=88=A4=E6=96=AD=E4=B8=8E=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复仅检测X轴到达目标就切换待机状态的问题,新增Y轴位置校验,确保XY轴均到达目标点后才切换为待机状态;修复平滑移动时强制重置Y轴位置的问题,改为仅更新X轴坐标并保留当前Y轴位置;在边界检测和微小位移判断逻辑中加入Y轴状态校验,避免移动中途错误切换状态。 --- assets/script/game/hero/MoveComp.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/assets/script/game/hero/MoveComp.ts b/assets/script/game/hero/MoveComp.ts index 7144fabd..a70d0cd6 100644 --- a/assets/script/game/hero/MoveComp.ts +++ b/assets/script/game/hero/MoveComp.ts @@ -263,7 +263,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate private moveToSlot(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, targetX: number) { const currentX = view.node.position.x; - if (Math.abs(currentX - targetX) <= 2) { + const currentY = view.node.position.y; + + // 当 X 和 Y 都到达目标时,才算真正到达 + if (Math.abs(currentX - targetX) <= 2 && Math.abs(currentY - move.baseY) <= 2) { view.node.setPosition(targetX, move.baseY, 0); view.status_change("idle"); return; @@ -283,14 +286,25 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX); const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX); const currentX = view.node.position.x; + const currentY = view.node.position.y; + const delta = speed * this.dt * direction; let newX = view.node.position.x + delta; if (currentX < moveMinX && direction < 0) { - view.status_change("idle"); + // X 轴到底了,如果 Y 轴还在换路,继续维持 move 状态 + if (Math.abs(currentY - move.baseY) > 2) { + view.status_change("move"); + } else { + view.status_change("idle"); + } return; } if (currentX > moveMaxX && direction > 0) { - view.status_change("idle"); + if (Math.abs(currentY - move.baseY) > 2) { + view.status_change("move"); + } else { + view.status_change("idle"); + } return; } newX = Math.max(moveMinX, Math.min(moveMaxX, newX)); @@ -299,10 +313,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX); } if (Math.abs(newX - currentX) < 0.01) { - view.status_change("idle"); + // X轴虽然没变化,但如果Y轴还在移动,依然是move状态 + if (Math.abs(currentY - move.baseY) > 2) { + view.status_change("move"); + } else { + view.status_change("idle"); + } return; } - view.node.setPosition(newX, move.baseY, 0); + view.node.setPosition(newX, view.node.position.y, 0); // 注意:这里只更新 X,Y 在外部平滑逻辑更新 view.status_change("move"); }