用户:
一只dog.创造师查看:0 回复:1 评论:0 创建时间:2022-06-28T20:58:39
怎么写剑气代码??????
跟发射子弹差不多,就是换了个模型,代码:
const Quat = new Box3Quaternion(0, 0, 0, 1); //初始化四元数,用于旋转
entity.player.onPress(async({ button,entity }) => {
if(button === Box3ButtonType.ACTION0){
let bullet = world.createEntity({ //创建一个子弹实体
mesh: //此处填剑气模型mesh, //模型为子弹模型
meshScale: [1/16, 1/16, 1/16], //大小为默认大小,[1/16, 1/16, 1/16]
collides: true, //开启碰撞
gravity: false, //不受重力影响
position: entity.player.position, //在玩家的位置生成子弹
meshOrientation: d.rotateY(Math.PI / 2), //子弹的头指向玩家,这里还需要用四元数的rotateY方法来旋转90度
});
bullet.onEntityContact(({ other }) => { //每当子弹碰到另一个实体
if (other.hp > 0) { //如果这个实体的血量大于0
other.hurt(10, { //被碰实体受10点伤害
damageType: '剑气', //伤害类型设为“炮台的子弹”
});
bullet.destroy(); //攻击之后子弹消失,防止重复攻击
}
});
await sleep(1500); //等1.5秒后
if (!bullet.destroyed) { //如果这个子弹还没有清除
bullet.destroy(); //清除子弹,防止子弹数量太多超过服务器负载
}
}
}, 2000);
});
点赞0
评论