用户:
YDS尹子查看:14 回复:17 评论:14 创建时间:2021-01-31T20:02:22
使用指南
对准方块或实体按下左键,喵会在大约5秒内抵达目标
准确度:
10格内:完全准确
操作指南
首先,放置一个名为"舰载激光炮"的模型,并添加标签"roclauncher".
其次,放置一个名为"鱼雷-火箭"的模型(这个模型是我拿鱼雷模型改的),并添加标签"roc".
然后,添加以下代码:
const Quat = new Box3Quaternion(0, 1, 0, 0)// box引擎默认的旋转朝向
const Quat2 = new Box3Quaternion(0, 1, 0, 0)// box引擎默认的旋转朝向
var roc = world.querySelector(".roc")
roc.meshOrientation.set(0, 1, -1, 0)
var readyTime=0.5;//装弹时间-秒
var flyTime=5;//飞行时长-秒
world.querySelectorAll(".roclauncher").forEach(async (e) => {
e.ready=true;//装弹完毕
})
world.onPress(({ entity, button, raycast: { hitPosition } }) => {
if (button == 'action1') {
// entity.velocity.y+=0.2;
// var direction = e.position.sub(hitPosition);
world.querySelectorAll(".roclauncher").forEach(async (e) => {
if(e.ready){
e.ready=false;
console.log(e.id)
var direction = hitPosition.sub(e.position);
var orientation = Quat.rotateY(Math.atan2(direction.z, direction.x))
var orientation2 = Quat2.rotateY(Math.atan2(direction.z, direction.x))
e.meshOrientation.copy(orientation)
var crted = world.createEntity();
crted.ctrl = false;
crted.meshOrientation.copy(orientation2);
crted.position.set(e.position.x, e.position.y, e.position.z);
crted.mesh = roc.mesh;
crted.meshScale = roc.meshScale;
crted.gravity = true; crted.fixed = false;
crted.launcher = e;
crted.addTag("lchr");
crted.mass = 1;
crted.particleLimit = 1000;
crted.particleRate = 1000;
crted.particleColor = [new Box3RGBColor(1, 1, 0), new Box3RGBColor(1, 0, 0)]
crted.particleSize = [5, 4]
crted.particleAcceleration.set(0, -5, 0)
crted.particleVelocitySpread.set(5, 1, 5);
crted.particleLifetime = 2;
crted.gravity = false;
crted.velocity.y = 2;
for (let i = 0; i < 10; i++) {
crted.velocity.x += direction.x / 200;
crted.velocity.z += direction.z / 200;
await sleep(30);
}
crted.tar = hitPosition;
crted.ctrl = true;
setTimeout(()=>{e.ready=true;},readyTime*1000)
setTimeout(() => { crted.destroy() }, flyTime*1000)
}else{
entity.player.directMessage("火箭炮装弹中...")
}
})
}
})
world.onVoxelContact(async ({ entity, x, y, z }) => {
if (entity.hasTag("lchr")) {
entity.particleVelocity.set(0, 30, 0);
await sleep(500);
entity.destroy()
}
})
world.onTick(() => {
world.querySelectorAll(".lchr").forEach((e) => {
var orientation2 = Quat2.rotateY(Math.atan2(e.velocity.z, e.velocity.x))
e.meshOrientation.copy(orientation2);
e.meshOrientation.y = -Math.atan2(e.velocity.y, Math.sqrt(e.velocity.x * e.velocity.x + e.velocity.z * e.velocity.z))
e.particleVelocity.set(-e.velocity.x, -e.velocity.y, -e.velocity.z);
if (e.ctrl) {
var direction = e.tar.sub(e.position);
e.velocity.x = (direction.x+direction.x/2) / 20;
e.velocity.y -= 0.1;
e.velocity.z = (direction.z+direction.z/2) / 20;
}
})
})