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"); }