feat(skill): add movement acceleration support for skills
1. 新增SMoveComp的isAccelerate字段控制加速逻辑 2. 添加技能配置is_accel字段启用加速效果 3. 实现二次方缓入加速曲线,兼顾起步速度与最终加速度 4. 为6001号技能默认开启加速效果并调整其移动类型为直线运动
This commit is contained in:
@@ -69,6 +69,9 @@ export class SMoveDataComp extends ecs.Comp {
|
||||
bezierMidHeight: number = 200;
|
||||
bezierArc: number = 1;
|
||||
|
||||
/** 是否逐渐加速 (ease-in) */
|
||||
isAccelerate: boolean = false;
|
||||
|
||||
/** 是否自动销毁(到达目标后) */
|
||||
autoDestroy: boolean = true;
|
||||
|
||||
@@ -80,6 +83,7 @@ export class SMoveDataComp extends ecs.Comp {
|
||||
this.bezierStartHeight = 30;
|
||||
this.bezierMidHeight = 200;
|
||||
this.bezierArc = 1;
|
||||
this.isAccelerate = false;
|
||||
this.speed = 500;
|
||||
this.progress = 0;
|
||||
this.scale = 1;
|
||||
@@ -181,14 +185,20 @@ export class SMoveDataComp extends ecs.Comp {
|
||||
* 根据移动类型计算当前位置
|
||||
*/
|
||||
private calculateCurrentPosition() {
|
||||
// 如果开启了逐渐加速,混合线性与二次方曲线 (如 0.7 * t^2 + 0.3 * t)
|
||||
// 这样起步拥有 30% 的基础速度,不会显得完全静止,随后逐渐加速
|
||||
const t = this.isAccelerate ?
|
||||
(this.progress * this.progress * 0.7 + this.progress * 0.3) :
|
||||
this.progress;
|
||||
|
||||
switch (this.runType) {
|
||||
case RType.linear:
|
||||
// 直线运动
|
||||
Vec3.lerp(this.currentPos, this.startPos, this.targetPos, this.progress);
|
||||
Vec3.lerp(this.currentPos, this.startPos, this.targetPos, t);
|
||||
break;
|
||||
|
||||
case RType.bezier:
|
||||
this.calculateBezierPosition(this.progress);
|
||||
this.calculateBezierPosition(t);
|
||||
break;
|
||||
|
||||
case RType.fixed:
|
||||
@@ -198,7 +208,7 @@ export class SMoveDataComp extends ecs.Comp {
|
||||
break;
|
||||
|
||||
default:
|
||||
Vec3.lerp(this.currentPos, this.startPos, this.targetPos, this.progress);
|
||||
Vec3.lerp(this.currentPos, this.startPos, this.targetPos, t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user