From b6efcdf794cedf5daee3a5ce08aca7eccb93836a Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 19 Mar 2026 10:19:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(skill):=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84rePos=E6=96=B9=E6=B3=95=E5=B9=B6?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=B4=9D=E5=A1=9E=E5=B0=94=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除SMoveDataComp中未使用的rePos方法以简化代码 - 在SMoveSystem中为贝塞尔移动类型实现完整的坐标计算逻辑 - 添加resolveBezierFinalXByHorizon方法计算水平线上的最终X坐标 --- assets/script/game/skill/SMoveComp.ts | 21 ------------------- assets/script/game/skill/SMoveSystem.ts | 27 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/assets/script/game/skill/SMoveComp.ts b/assets/script/game/skill/SMoveComp.ts index 88ff0582..0f057ceb 100644 --- a/assets/script/game/skill/SMoveComp.ts +++ b/assets/script/game/skill/SMoveComp.ts @@ -90,27 +90,6 @@ export class SMoveDataComp extends ecs.Comp { this.autoDestroy = true; } - /** - * 重新计算位置(用于线性移动的延长) - */ - rePos(originalStart: Vec3) { - if (!originalStart) { - return; - } - - // 计算方向向量 - const direction = new Vec3(); - Vec3.subtract(direction, this.targetPos, originalStart); - direction.normalize(); - - // 延长720像素 - const extendedTarget = new Vec3(); - Vec3.scaleAndAdd(extendedTarget, originalStart, direction, 720); - - this.startPos.set(originalStart); - this.targetPos.set(extendedTarget); - } - /** * 开始移动 */ diff --git a/assets/script/game/skill/SMoveSystem.ts b/assets/script/game/skill/SMoveSystem.ts index 571abba0..9d866c95 100644 --- a/assets/script/game/skill/SMoveSystem.ts +++ b/assets/script/game/skill/SMoveSystem.ts @@ -103,8 +103,22 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate node.setPosition(moveComp.targetPos.x > 360 ? 300 : moveComp.targetPos.x, node.position.y, 0); break; case RType.bezier: - // - return + const bezierStartPos = v3( + moveComp.startPos.x + moveComp.atk_x, + moveComp.startPos.y + moveComp.atk_y, + moveComp.startPos.z + ); + const bezierTargetPos = v3( + moveComp.targetPos.x + moveComp.atk_x, + moveComp.targetPos.y + moveComp.atk_y, + moveComp.targetPos.z + ); + const horizonY = bezierStartPos.y; + const finalX = this.resolveBezierFinalXByHorizon(bezierStartPos, bezierTargetPos, horizonY); + moveComp.startPos.set(bezierStartPos); + moveComp.targetPos.set(finalX, horizonY, bezierTargetPos.z); + node.setPosition(bezierStartPos); + break; default: // 其他类型(包括bezier):根据atk_x和atk_y调整起始位置 if (moveComp.atk_x !== 0 || moveComp.atk_y !== 0) { @@ -119,6 +133,15 @@ export class SMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate break; } } + + private resolveBezierFinalXByHorizon(startPos: Vec3, targetPos: Vec3, horizonY: number): number { + const deltaY = targetPos.y - startPos.y; + if (Math.abs(deltaY) < 0.0001) { + return targetPos.x; + } + const t = (horizonY - startPos.y) / deltaY; + return startPos.x + (targetPos.x - startPos.x) * t; + } update(entity: ecs.Entity): void { if(!smc.mission.play ) return;