refactor(skill): 移除未使用的rePos方法并实现贝塞尔移动逻辑

- 删除SMoveDataComp中未使用的rePos方法以简化代码
- 在SMoveSystem中为贝塞尔移动类型实现完整的坐标计算逻辑
- 添加resolveBezierFinalXByHorizon方法计算水平线上的最终X坐标
This commit is contained in:
panw
2026-03-19 10:19:55 +08:00
parent 7415626395
commit b6efcdf794
2 changed files with 25 additions and 23 deletions

View File

@@ -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);
}
/**
* 开始移动
*/

View File

@@ -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;