用户:
呵呵0486查看:11 回复:10 评论:11 创建时间:2022-12-21T12:09:51
嗯首先我们先搞2个模型:灯和单元方块()
然后呢我们再在论坛里找几个大佬的代码()
function addlaser(start,end){
const Quat = new Box3Quaternion(0,0,0,1);
function addlaser(start,end){
const distance = start.distance(end);
const laser = world.createEntity({
mesh: 'mesh/激光.vb',
meshScale: [0.0625*distance,0.0625,0.0625],
gravity: false,
collides: false,
fixed: true,
position: start.lerp(end,0.5),
})
const d = start.sub(end);
laser.meshOrientation = Quat.rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x));
const points = [];
for(let i=0;i<distance;i+=0.1){
points.push({
lo: start.lerp(end,0.1*distance*i),
hi: start.lerp(end,0.1*distance*i),
})
}
world.onTick(()=>{
points.forEach((e)=>{
world.searchBox(e).forEach((e)=>{
if(e.isPlayer){
e.hurt(100);
}
})
})
})
}
}
(转自:Lolita 帖号:https://shequ.codemao.cn/community/387107)
const e1 = world.querySelector('#旋转实体');
world.onTick(async({tick})=>{
const e2 = world.querySelectorAll('player')
e2.forEach((e) =>{
e1.position.y = e.position.y;
e1.position.x = e.position.x + Math.cos(tick/5)*5
e1.position.z = e.position.z + Math.sin(tick/5)*5
})
})
(转自:浮生 帖号:https://shequ.codemao.cn/community/423452)
然后再稍微改一点点()
var pos = new Box3Vector3(0,0,0)/*这里面的数字填啥都行,没有影响*/
var tick = 0
setInterval(async() => {
tick += 1
},50)
setInterval(async () => {
world.querySelectorAll('#地图内灯的名字').forEach((x) => {
pos.x = x.position.x + Math.cos(tick / 喵0/*可以改 越大旋转越慢*/) * 104/*可以改 越大旋转的半径也越大*/
pos.z = x.position.z + Math.sin(tick / 喵0/*可以改 越大旋转越慢*/) * 104/*可以改 越大旋转的半径也越大*/
const light = world.createEntity({
mesh:'mesh/单元方块.vb',
meshScale:[1/16*x.position.distance(pos),1/16,1/16],
position:x.position.lerp(pos,0.5),
gravity:false,
collides:false,
fixed:true,
meshEmissive:true
})
const d = x.position.sub(pos);
light.meshOrientation = new Box3Quaternion(0,0,0,1).rotateX(Math.atan2(d.y,Math.sqrt(d.x**2+d.z**2))).rotateY(Math.atan2(d.z,d.x));
sleep(110).then(async() => {
light.destroy()
})
})
},100)
就行了()