Lv.1
在 【求助】这报错就离谱 中回复
为啥你在代码截图里没有导入entity这个参数,一般这个报错是在entity不是玩家的时候触发的,你最好在onPress里在导入一个entity,还有你到底在外面套了个啥,world.onPress是不需要在玩家触发的代码里写的,直接写在最外层就好了,如果你是要搞玩家的区别对待的话,你在onpress里用entity进行判定,而且onpress只能是玩家触发的,所以你不要有顾虑。
2022-08-09T21:32:57 点赞:0
在 《论TNT的破坏性以及其代码》 中回复
async function tnt(x,y,z){
const e=world.createEntity({
mesh:"mesh/TNT.vb",
meshScale:[1/16,1/16,1/16],
collides:true,
gravity:false,
friction:1.5,
position:[x,y,z],
})
e.enableDamage=true
e.fixed=true
e.maxHp=1
e.hp=1
e.addTag("TNT")
e.showHealthBar=false
e.onTakeDamage(async()=>{e.enableDamage=false
e.gravity=true
e.fixed=false
for(i=0;i<3;i++){
e.meshEmissive = 1
await sleep(500)
e.meshEmissive = 0
await sleep(500)}
const bounds = new Box3Bounds3(new Box3Vector3(e.position.x-4,e.position.y-4,e.position.z-4), new Box3Vector3(e.position.x+4,e.position.y+4,e.position.z+4))
world.searchBox(bounds).forEach((entityInBounds) => {
entityInBounds.hurt(10,{attacker:"TNT"})
var direction = entityInBounds.position.sub(e.position)
if(direction.x>0){entityInBounds.velocity.x+=1}else{entityInBounds.velocity.x-=1}
if(direction.y>0){entityInBounds.velocity.y+=1}else{entityInBounds.velocity.y-=1}
if(direction.z>0){entityInBounds.velocity.z+=1}else{entityInBounds.velocity.z-=1}
})
sphere("air",e.position.x,e.position.y,e.position.z,3)
e.destroy()})}
world. onPress(({button, raycast: { voxelIndex, normal}}) =>{
if (button == Box3ButtonType.ACTION1){
let v = voxelIndex.add(normal)
tnt(Math.round(v.x)+0.5,v.y+0.5,Math.round(v.z)+0.5)}})
world.onClick(({entity,button})=>{
if(entity.hasTag("TNT")&&button=="action1"){
entity.hurt(1)
}})
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++){
let dx = x-cx;
let dy = y-cy;
let dz = z-cz;
if(Math.round(Math.sqrt(dx*dx+dy*dy+dz*dz)) <= radius){
voxels.setVoxel(x,y,z,vox)
}
}}}
}2022-08-22T08:41:49 点赞:0
在 求助,怎么在box3写点击实体就可以和它互动的程序,急! 中回复
world.onclick(({clicker})=>{
const result = await clicker.player.dialog({
type: Box3DialogType.SELECT,
title: "ababab",
content: `${entity.player.name}`,
options: ['a', 'b','c'],
})
if(!result || result === null){
return;
}})2022-08-26T10:44:02 点赞:0
在 招人招人招人!!!! 中回复
https://box3.cod喵/e/6a51b8c0f9826182ae98?p=IThmrFXso2CU53nzFMx3f%2BFHrTXn3ie1JPICHbOSW%2FA7%2BonkOuMAVndWVzdA%3D%3D
2022-08-28T15:01:27 点赞:0
在 【社区功能反馈】用心倾听,用头发发电!(2026更新版) 中回复
技术喵,为什么我在创作端都测试没问题的东西在发布端就没反应了,希望可以把这个bug修好
2022-08-29T16:33:59 点赞:0
在 求助,是我的问题还是岛三的问题 中回复
https://box3.codemao.cn/e/6a51b8c0f9826182ae98?p=SJp2vZH6CLWFluegg9yJIcFGv4Td3zmUBqLGm6vAFVA93i6y6zMAVndWVzdA%3D%3D
2022-09-12T15:58:24 点赞:0