做了个粗暴的方案…尽量维持Tween的调用方式…看看引擎组后面有没有其他计划吧…
(实现的不是贝塞尔…是基于y轴的抛物线…毕竟我的需求是这个…)
// 调用
tween(this.node)
.by(0.5, { position: new Vec3(0, 50, 0) }, { easing: easing.backOut })
.delay(0.5)
.to(0.5, { worldPosition: Utils.jumpTo_v3(targetNode.worldPosition, 200) }, { easing: easing.sineInOut })
.call(() => { console.log("[tween][end]"); })
.start();
// 实现 Util.ts
import { math, Vec2, Vec3 } from "cc";
export class Utils {
static jumpTo_v3(to: Vec3, height: number): Readonly<Vec3> {
return { value: to, progress: this._jumpTo_progress(3, height) } as any as Vec3;
}
static jumpTo_v2(to: Vec3, height: number): Readonly<Vec2> {
return { value: to, progress: this._jumpTo_progress(2, height) } as any as Vec2;
}
private static _jumpTo_progress(max: number, height: number): (from: number, to: number, cur: number, pcs: number) => number {
let i = max;
let heightSqrt = Math.sqrt(height);
return (from: number, to: number, cur: number, pcs: number) => {
// 使用序列耦合区分xyz轴: 1: x, 2: y, 3: z
if (i >= max) i = 1;
else i++;
// let rsl = from + (to - from) * pcs; // lerp
let rsl = math.lerp(from, to, pcs);
if (i === 2) { // y轴的增量算法
let du = Math.abs(1 - pcs * 2); // [0,1] > [1,0,1]
rsl += height - Math.pow(heightSqrt * du, 2);
}
return rsl;
};
}
}