//射出追踪子弹
protected override update(): void {
this.loveStarArray.forEach((data) => {
const { node, roleNode } = data;
if (cc.isValid(node) && cc.isValid(roleNode)) {
const rolePosition = this.node.convertToNodeSpaceAR(
roleNode.parent.convertToWorldSpaceAR(roleNode.getPosition())
);
rolePosition.y += 126 + Utils.random(-this.diff, this.diff);
rolePosition.x += Utils.random(-this.diff, this.diff);
const nodePosition = node.getPosition();
const distance = rolePosition.sub(nodePosition); //当前和目标之间的带方向距离
const moveDistance = distance.normalize().mul(10); //每次移动10个归一化单位
node.setPosition(nodePosition.add(moveDistance)); //更改当前坐标
//scale越来越大
node.scale < 2 ? (node.scale += 0.012) : '';
if (distance.mag() < 10) {
//距离小于10时销毁
node.destroy();
}
}
});
//过滤已销毁节点
this.loveStarArray = this.loveStarArray.filter((data) => {
return cc.isValid(data.node);
});
}
cocosCreator追踪型子弹核心逻辑
最新推荐文章于 2024-10-09 18:56:06 发布