比如说节点1从坐标A移动到坐标B
用向量做插值
startPos = new Vec3(100, 100); // 起始坐标 A
endPos = new Vec3(400, 400); // 目标坐标 B
moveDuration = 2; // 移动时长(秒)
// 记录当前时间和移动的进度
elapsedTime = 0;
start() {
// 初始化节点位置
this.node.setPosition(this.startPos);
}
update(dt: number) {
this.elapsedTime += dt;
let progress = this.elapsedTime / this.moveDuration;
if (progress > 1) {
progress = 1;
}
const newPos = this.startPos.lerp(this.endPos, progress);
// 设置节点的新位置
this.node.setPosition(newPos);
// 移动完成后的操作
if (progress === 1) {
console.log(“移动完成”);
this.enabled = false;
}
}
tween就可以了
+10086