用户:
来自代码岛的鬼影迷踪查看:3 回复:2 评论:3 创建时间:2022-09-07T18:50:22
链接:https://box3.codemao.cn/e/2ef1c喵c3c5aa8da69a7
招代码(修bug)
找建筑(建筑一点没动)
找封面(作者不会做)
不想来的帮我看看右键怎么了,TNt为什么不能破坏//
var re = []
world.onPlayerJoin(({ entity }) => {
entity.player.enable3DCursor = true // 开启方块光标
entity.id_player = 127
entity.rotate_player = 0
entity.white = false;
entity.whiten = 0;
entity.whitet = 0;
entity.voxelIndex1 = null;
world.onTick(({ tick }) => {
if (entity.white) {
entity.whiten++;
if (entity.whiten >= entity.whitet) {
voxels.setVoxelId(entity.voxelIndex1.x, entity.voxelIndex1.y, entity.voxelIndex1.z, voxels.id('air'))
entity.white = false;
}
}
else {
whiten = 0;
entity.voxelIndex1 = null;
}
})
})
world.onPress(({ entity, voxel, button, raycast }) => { //方块放置与销毁
re = [];
if (button === Box3ButtonType.ACTION0 && raycast.voxelIndex.distance(entity.position) <= 6 && entity.shortcut_bar.length > entity.sci) {
switch (voxels.getVoxel(raycast.voxelIndex.x, raycast.voxelIndex.y, raycast.voxelIndex.z)) {
case voxels.id('white'):
entity.voxelIndex1 = raycast.voxelIndex
entity.white = true;
entity.whiten = 0;
entity.whitet = 20;
if (entity.shortcut_bar[entity.sci][0] == '剪刀') {
entity.whitet -= 17
}
break;
case voxels.id('sand'):
entity.voxelIndex1 = raycast.voxelIndex
entity.white = true;
entity.whiten = 0;
entity.whitet = 65;
if (entity.shortcut_bar[entity.sci][0] == '木镐') {
entity.whitet -= 20
}
if (entity.shortcut_bar[entity.sci][0] == '石镐') {
entity.whitet -= 30
}
if (entity.shortcut_bar[entity.sci][0] == '铁镐') {
entity.whitet -= 40
}
if (entity.shortcut_bar[entity.sci][0] == '钻石镐') {
entity.whitet -= 50
}
break;
case voxels.id('lemon'):
entity.voxelIndex1 = raycast.voxelIndex
entity.white = true;
entity.whiten = 0;
entity.whitet = 100;
if (entity.shortcut_bar[entity.sci][0] == '木镐') {
entity.whitet -= 40
}
if (entity.shortcut_bar[entity.sci][0] == '石镐') {
entity.whitet -= 50
}
if (entity.shortcut_bar[entity.sci][0] == '铁镐') {
entity.whitet -= 60
}
if (entity.shortcut_bar[entity.sci][0] == '钻石镐') {
entity.whitet -= 80
}
break;
case voxels.id('plank_02'):
entity.voxelIndex1 = raycast.voxelIndex
entity.white = true;
entity.whiten = 0;
entity.whitet = 85;
if (entity.shortcut_bar[entity.sci][0] == '木斧') {
entity.whitet -= 30
}
if (entity.shortcut_bar[entity.sci][0] == '石斧') {
entity.whitet -= 40
}
if (entity.shortcut_bar[entity.sci][0] == '铁斧') {
entity.whitet -= 50
}
if (entity.shortcut_bar[entity.sci][0] == '钻石斧') {
entity.whitet -= 70
}
break;
case voxels.id('black'):
entity.voxelIndex1 = raycast.voxelIndex
entity.white = true;
entity.whiten = 0;
entity.whitet = 500;
if (entity.shortcut_bar[entity.sci][0] == '木镐') {
entity.whitet -= 300
}
if (entity.shortcut_bar[entity.sci][0] == '石镐') {
entity.whitet -= 350
}
if (entity.shortcut_bar[entity.sci][0] == '铁镐') {
entity.whitet -= 400
}
if (entity.shortcut_bar[entity.sci][0] == '钻石镐') {
entity.whitet -= 450
}
break;
}
} else if (button === Box3ButtonType.ACTION1) {
if (entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '羊毛') {
const pos = raycast.voxelIndex.add(raycast.normal)
if (pos.distance(entity.position) <= 6) {
const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
let s = true
world.querySelectorAll('player').forEach(async (x) => {
if (x.collides && (Math.floor(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.floor(x.position.y) + 1 == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) - 1 == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z)) {
s = false
}
})
var a = [[14, 11, 132], [108, 11, 240], [200, 11, 128], [106, 11, 14]];
a.forEach((i) => {
if ([i[0], i[1], i[2]] == [pos.x, pos.y, pos.z] || [i[0], i[1] - 1, i[2]] == [pos.x, pos.y, pos.z]) { s = false; }
})
if (s) {
voxels.setVoxel(pos.x, pos.y, pos.z, 'white')
entity.shortcut_bar[entity.sci][3]--;
}
}
}
if (entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '沙石') {
const pos = raycast.voxelIndex.add(raycast.normal)
if (pos.distance(entity.position) <= 6) {
let s = true
world.querySelectorAll('player').forEach(async (x) => {
if (x.collides && (Math.floor(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.floor(x.position.y) + 1 == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) - 1 == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z)) {
s = false
}
})
var a = [[14, 11, 132], [108, 11, 240], [200, 11, 128], [106, 11, 14]];
a.forEach((i) => {
if ([i[0], i[1], i[2]] == [pos.x, pos.y, pos.z] || [i[0], i[1] - 1, i[2]] == [pos.x, pos.y, pos.z]) { s = false; }
})
if (s) {
const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
voxels.setVoxel(pos.x, pos.y, pos.z, 'sand')
entity.shortcut_bar[entity.sci][3]--;
}
}
}
if (entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '末地石') {
const pos = raycast.voxelIndex.add(raycast.normal)
if (pos.distance(entity.position) <= 6) {
let s = true
world.querySelectorAll('player').forEach(async (x) => {
if (x.collides && (Math.floor(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.floor(x.position.y) + 1 == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) - 1 == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z)) {
s = false
}
})
var a = [[14, 11, 132], [108, 11, 240], [200, 11, 128], [106, 11, 14]];
a.forEach((i) => {
if ([i[0], i[1], i[2]] == [pos.x, pos.y, pos.z] || [i[0], i[1] - 1, i[2]] == [pos.x, pos.y, pos.z]) { s = false; }
})
if (s) {
const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
voxels.setVoxel(pos.x, pos.y, pos.z, 'lemon')
entity.shortcut_bar[entity.sci][3]--;
}
}
}
if (entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '黑曜石') {
const pos = raycast.voxelIndex.add(raycast.normal)
if (pos.distance(entity.position) <= 6) {
let s = true
world.querySelectorAll('player').forEach(async (x) => {
if (x.collides && (Math.floor(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.floor(x.position.y) + 1 == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) - 1 == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z)) {
s = false
}
})
var a = [[14, 11, 132], [108, 11, 240], [200, 11, 128], [106, 11, 14]];
a.forEach((i) => {
if ([i[0], i[1], i[2]] == [pos.x, pos.y, pos.z] || [i[0], i[1] - 1, i[2]] == [pos.x, pos.y, pos.z]) { s = false; }
})
if (s) {
voxels.setVoxel(pos.x, pos.y, pos.z, 'white')
}
if (s) {
const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
voxels.setVoxel(pos.x, pos.y, pos.z, 'black')
entity.shortcut_bar[entity.sci][3]--;
}
}
}
if (entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '木板') {
const pos = raycast.voxelIndex.add(raycast.normal)
if (pos.distance(entity.position) <= 6) {
let s = true
world.querySelectorAll('player').forEach(async (x) => {
if (x.collides && (Math.floor(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.floor(x.position.y) + 1 == raycast.voxelIndex.add(raycast.normal).y && Math.floor(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.floor(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z) || (Math.ceil(x.position.y) - 1 == raycast.voxelIndex.add(raycast.normal).y && Math.ceil(x.position.x) == raycast.voxelIndex.add(raycast.normal).x && Math.ceil(x.position.z) == raycast.voxelIndex.add(raycast.normal).z)) {
s = false
}
})
var a = [[14, 11, 132], [108, 11, 240], [200, 11, 128], [106, 11, 14]];
a.forEach((i) => {
if ([i[0], i[1], i[2]] == [pos.x, pos.y, pos.z] || [i[0], i[1] - 1, i[2]] == [pos.x, pos.y, pos.z]) { s = false; }
})
if (s) {
voxels.setVoxel(pos.x, pos.y, pos.z, 'white')
}
if (s) {
const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
voxels.setVoxel(pos.x, pos.y, pos.z, 'plank_02')
entity.shortcut_bar[entity.sci][3]--;
}
}
}
}
})
world.onPress(async ({ button, entity, position, pressed, raycast, tick }) => { //近战武器伤害
if (!entity.none) {
if (button === 'action0' && entity.hp > 0 && entity.canj) {
if (raycast.hitEntity && entity.isPlayer && raycast.hitEntity.isPlayer && raycast.hitPosition.distance(entity.position) <= 10 && entity.h && raycast.hitEntity.team != entity.team) {
if (entity.ld) { //如果连点开启
}
else {
entity.h = false;
const facing = entity.player.facingDirection//玩家的朝向
let jitui = 0.5 //击退距离
if (entity.ymz || entity.shortcut_bar.length > entity.sci && entity.shortcut_bar[entity.sci][0] == '击退棒') {
jitui = 3;
}
if (entity.shortcut_bar.length > entity.sci) {
switch (entity.shortcut_bar[entity.sci][0]) {
case '木剑':
jitui += 0.2;
break;
case '石剑':
jitui += 0.3;
break;
case '铁剑':
jitui += 0.5;
case '钻石剑':
jitui += 0.8;
case '下界合金剑':
jitui += 0.9
}
}
const tgPos = raycast.hitEntity.position//僚机的目标位置
const ratio = 1.0//追随的灵敏度, 最好设在0.5左右, 1.0表示立即移到玩家位置
const budPos = raycast.hitEntity.position//僚机的当前位置
const xOffset = facing.x * jitui
const zOffset = facing.z * jitui
const xDiff = tgPos.x - budPos.x
const zDiff = tgPos.z - budPos.z
const 喵 = (xDiff + xOffset) * ratio
const vz = (zDiff + zOffset) * ratio
raycast.hitEntity.velocity.set(喵, raycast.hitEntity.velocity.y, vz)
entity.sh = Math.round(Math.random()) + 1;
if (entity.ymz || entity.shortcut_bar.length > entity.sci && entity.shortcut_bar[entity.sci][0] == '击退棒') {
entity.sh = Math.round(Math.random());
}
if (entity.shortcut_bar.length > entity.sci) {
switch (entity.shortcut_bar[entity.sci][0]) {
case '木剑':
entity.sh += 3;
break;
case '石剑':
entity.sh += 4;
break;
case '铁剑':
entity.sh + 6;
break;
case '钻石剑':
entity.sh += 6;
break;
case '下界合金剑':
entity.sh += 8.5;
break;
}
}
raycast.hitEntity.player.directMessage(`你受到了来自${entity.player.name}的${entity.sh}点伤害`)
raycast.hitEntity.hurt(entity.sh);
raycast.hitEntity.damage = entity;
await sleep(300)
entity.h = true;
await sleep(20000 - 300)
raycast.hitEntity.damage = null;
}
}
}
}
})
world.onPress(async ({ button, entity, position, pressed, raycast, tick }) => {
var len = 0;
var i = 0;
if (entity.shortcut_bar.length > entity.sci) {
world.trans.forEach((item) => {
if (item[0] == entity.shortcut_bar[entity.sci][0]) {
len = i;
return;
}
i += 1;
})
}
if (len < 14 && len > 4 && (button == 'action0' || button == 'action1')) { entity.shortcut_bar[entity.sci][3]--; }
if (button == 'action1' && entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == 'TNT') {
const tnt = world.createEntity({
mesh: 'mesh/TNT.vb',
meshScale: [1 / 16, 1 / 16, 1 / 16],
fixed: true,
gravity: true,
collides: true,
position: [raycast.voxelIndex.add(raycast.normal).x + 0.5, raycast.voxelIndex.add(raycast.normal).y + 0.5, raycast.voxelIndex.add(raycast.normal).z + 0.5]
})
t = 4;
t *= 4;
while (t > 0) {
if (tnt.meshEmissive == 0) {
tnt.meshEmissive = 1;
} else {
tnt.meshEmissive = 0;
}
t--;
await sleep(500)
}
tnt.destroy()
world.querySelectorAll('player').forEach((x) => {
if (x.position.distance(tnt.position) <= 10) {
var ts = Math.round(Math.random() * 2 + 3);
x.hurt(ts)
x.player.directMessage('你受到了来自' + entity.player.name + '的' + ts + '点伤害')
var direction = raycast.voxelIndex.sub(x.position)
var dist = direction.mag()
x.velocity.x += direction.x * 3 / dist * -1
x.velocity.y += 1;
x.velocity.z += direction.z * 3 / dist * -1
}
})
world.querySelectorAll('.tnt').forEach((x) => {
if (x.position.distance(tnt.position) <= 10) {
x.hurt(Math.round(Math.random() * 2 + 3))
var direction = raycast.voxelIndex.sub(x.position)
var dist = direction.mag()
x.velocity.x += direction.x * 3 / dist * -1
x.velocity.y += 1;
x.velocity.z += direction.z * 3 / dist * -1
}
})
sphere('air', Math.floor(tnt.position.x), Math.floor(tnt.position.y), Math.floor(tnt.position.z, 5))
}
if (button == 'action1' && entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '火焰弹') {
const tnt = world.createEntity({
mesh: 'mesh/火焰弹.vb',
meshScale: [1 / 16, 1 / 16, 1 / 16],
fixed: false,
collides: true,
velocity: false,
meshOrientation: new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(raycast.direction.z, raycast.direction.x)).rotateY(Math.PI / 2),
id: '火焰弹',
velocity: raycast.direction.mul(new Box3Vector3(1, 1, 1)),
position: entity.position
})
var xzCo = 0.44921875
var yCo = 1.6
tnt.t = world.onTick(({ tick }) => {
if (tnt.velocity != raycast.direction.mul(new Box3Vector3(1, 1, 1))) tnt.velocity = raycast.direction.mul(new Box3Vector3(1, 1, 1))
})
tnt.onEntityContact(({ other }) => {
var ts = Math.round(Math.random() * 2 + 3);
var x = other;
x.hurt(ts)
x.player.directMessage('你受到了来自' + entity.player.name + '的' + ts + '点伤害')
var direction = raycast.voxelIndex.sub(x.position)
var dist = direction.mag()
x.velocity.x += direction.x * 3 / dist * -1
x.velocity.y += 5;
x.velocity.z += direction.z * 3 / dist * -1
})
tnt.onVoxelContact(({ }) => {
world.querySelectorAll('player').forEach((x) => {
if (x.position.distance(tnt.position) <= 2) {
var ts = Math.round(Math.random() * 2 + 3);
x.hurt(ts)
x.player.directMessage('你受到了来自' + entity.player.name + '的' + ts + '点伤害')
var direction = raycast.voxelIndex.sub(x.position)
var dist = direction.mag()
x.velocity.x += direction.x * 3 / dist * -1
x.velocity.y += 5;
x.velocity.z += direction.z * 3 / dist * -1
}
})
tnt.destroy()
})
tnt.onDestroy(({ }) => {
tnt.t.cancel()
})
} if (button == 'action1' && entity.sc != '空' && entity.shortcut_bar[entity.sci][0] == '末影珍珠') {
const e = world.createEntity({
mesh: 'mesh/末影珍珠.vb',
position: entity.position,
gravity: true,
fixed: false,
velocity: raycast.direction.mul(new Box3Vector3(3, 3, 3)),
meshScale: new Box3Vector3(0.1, 0.1, 0.1),
meshOrientation: new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(raycast.direction.z, raycast.direction.x)).rotateY(Math.PI / 2),
});
e.t = world.onTick(({ tick }) => {
if (e.velocity != raycast.direction.mul(new Box3Vector3(1, 1, 1))) e.velocity = raycast.direction.mul(new Box3Vector3(1, 1, 1))
})
e.onDestroy(({ }) => {
e.t.cancel()
})
const chaoxiang = entity.player.facingDirection
e.position.copy(entity.position)
e.velocity = chaoxiang.scale(2)
e.velocity.y = raycast.direction.y * 2;
e.onVoxelContact(({ x, y, z }) => {
entity.position.set(e.position.x, e.position.y, e.position.z)
e.destroy()
})
e.onEntityContact(() => {
entity.position.copy(e.position)
e.destroy()
})
await sleep(5000)
} if (button == 'action1' && entity.sc != '弓' && entity.shortcut_bar[entity.sci][0] == '弓箭'&& starting == false &&startgame == false) {
var speed = 1
entity.player.walkState *= 0.5;
entity.player.walkAcceleration *= 0.5;
entity.player.runSpeed *= 0.5;
entity.player.runAcceleration *= 0.5;
while (entity.player.action0Button) {
if (speed < 10) {
speed++
}
await sleep(500);
entity.player.directMessage('蓄力:' + speed + '/10')
}
shootGJ(entity, speed)
entity.player.walkState *= 2;
entity.player.walkAcceleration *= 2;
entity.player.runSpeed *= 2;
entity.player.runAcceleration *= 2;
}
})
async function sphere(vox, cx, cy, cz, radius) {//嘿嘿嘿
let xend = cx + radius
let yend = cy + radius
let zend = cz + radius
for (let x = cx - radius; x <= xend; x++) {
for (let y = cy - radius; y <= yend; y++) {
for (let z = cz - radius; z <= zend; z++) {
if (new Box3Vector3(x, y, z).distance(new Box3Vector3(cx, cy, cz)) <= radius && voxels.getVoxelId(x, y, z) == voxels.id('white')) {
voxels.setVoxel(x, y, z, vox)
}
if (new Box3Vector3(x, y, z).distance(new Box3Vector3(cx, cy, cz)) <= radius && voxels.getVoxelId(x, y, z) == voxels.id('plank_02')) {
voxels.setVoxel(x, y, z, vox)
}
if (new Box3Vector3(x, y, z).distance(new Box3Vector3(cx, cy, cz)) <= radius && voxels.getVoxelId(x, y, z) == voxels.id('sand')) {
voxels.setVoxel(x, y, z, vox)
}
if (new Box3Vector3(x, y, z).distance(new Box3Vector3(cx, cy, cz)) <= radius && voxels.getVoxelId(x, y, z) == voxels.id('lemon')) {
voxels.setVoxel(x, y, z, vox)
}
}
}
}
}
world.onRelease(({ entity, voxel, button, raycast }) => {
if (entity.white) {
entity.white = false;
if (entity.whiten >= entity.whitet) {
voxels.setVoxelId(entity.voxelIndex1.x, entity.voxelIndex1.y, entity.voxelIndex1.z, voxels.id('air'))
}
}
})
const Quat1 = new Box3Quaternion(1, 1, 1, 1)
function getOrientationByVector(vector3) {
const src = vector3
let dx = src.x
let dy = src.y
let dz = src.z
let dist = Math.sqrt(dx * dx + dz * dz)
const rotx = Math.atan2(dy, dist)
return Quat1.rotateX(rotx).rotateY(Math.atan2(dz, dx))
}
console.clear()
const zdQuat = new Box3Quaternion(-0.676, 0.637, -0.301, 0.223)
async function shootGJ(entity, speed) {//射击弓箭
var e = world.createEntity({
mesh: 'mesh/箭.vb',
position: entity.position.add(new Box3Vector3(0, 1, 0)),//防卡
collides: true,//碰撞
meshScale: new Box3Vector3(0.07, 0.07, 0.07),
//gravity:true,
})
e.addTag('弓箭')
e.zhongli = 0.1;
var angle = Math.atan2(entity.player.facingDirection.z, entity.player.facingDirection.x)
e.velocity.x = Math.cos(angle) * Math.cos(-entity.player.cameraPitch) * speed
e.velocity.y = Math.sin(-entity.player.cameraPitch) * speed
e.velocity.z = Math.sin(angle) * Math.cos(-entity.player.cameraPitch) * speed
var orientation = zdQuat.rotateY(Math.atan2(e.velocity.z, e.velocity.x)).rotateX(-entity.player.cameraPitch)
e.meshOrientation.copy(orientation)
Object.assign(e, {
particleRate: 30,
particleLifetime: 3,
})
e.onEntityContact(({ other }) => {
if (other.isPlayer && other != entity) {
other.hurt(10 + speed * 2)
}
e.destroy()
})
e.onVoxelContact(({ }) => {
e.destroy()
})
await sleep(15000);
e.destroy()
}
(async function () {
for (let i = 0; i < Infinity; i++) {
world.querySelectorAll('.弓箭').forEach((e) => {
e.velocity.y -= e.zhongli
})
await sleep(100)
}
})()
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
})