have we any system or library this for create path for tween .
with that you can give bézier curve to a line and tween will follow that.
can we do some thing like this in cocos creator ?
I don’t think so, there’s no such thing as path BUT If you need to move something from A → B → C than you can take inspiration from this project GitHub - theRenard/cocos-creator-laser-defender: Laser Defender game tutorial. Here I’ve defined paths as a series of point and iterate through them with a tween.
import { _decorator, Component, Node, tween } from "cc";
const { ccclass, property } = _decorator;
import { WaveConfig } from "./WaveConfig";
@ccclass("Enemy")
export class Enemy extends Component {
waveConfig: WaveConfig = null;
waypoints: Node[] = [];
waypointIndex = 0;
start() {
this.waveConfig = this.node.parent.getComponent(WaveConfig);
this.waypoints = this.waveConfig.getWaypoints();
this.node.setPosition(this.waypoints[this.waypointIndex].position);
this.followPath();
}
followPath() {
const pathAnimation = tween(this.node);
for (let i = 1; i < this.waypoints.length; i++) {
pathAnimation.to(
this.waveConfig.getDuration(),
{
position: this.waypoints[i].position,
},
{
onComplete: () => {
if (i === this.waypoints.length - 1) {
this.node.destroy();
}
},
}
);
}
pathAnimation.start();
}
}