用户:
Star_Ink_sans查看:40 回复:26 评论:40 创建时间:2022-03-15T09:14:09
Hi,这里是Star_Ink_sans~
今天给大家介绍一些跑酷常用代码~
1.跑酷基本功能
//跑酷功能
for (const e of world.querySelectorAll('*')) {//遍历所有实体
if (e.id.startsWith('存档点')) {
e.collides = true //开启碰撞
e.fixed = true //固定实体不被推移
e.meshScale = e.meshScale.scale(2) //放大零倍
e.onEntityContact(({ other }) => {
if (other.isPlayer) {
if (e.position !== other.player.spawnPoint) {
other.player.directMessage('到达新的存档点')
other.player.spawnPoint = e.position // 玩家重生点坐标设置成存档点的坐标
}
}
})
}
}
world.onPlayerJoin(({ entity }) => {
entity.onFluidEnter(() => {//当玩家掉到水里
entity.position.copy(entity.player.spawnPoint)
entity.position.y += 4
})
})
注意:1.使用时请把存档点设置成存档点-1,存档点-2,etc的形式
2.我个人不推荐使用方块存档,因为有时会出一些奇奇怪怪的bug,这里不详
2.创作者降临!
const FRIEND_PLAYER = ['Star_Ink_sans','A','B','C','.....']
world.onPlayerJoin(({ entity }) => {
if (!FRIEND_PLAYER.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
world.say(`地图创作人员 ${entity.player.name} 降临!`)
entity.player.canFly = true;
})
注意:列表可以更改~
3.关闭玩家碰撞
world.addCollisionFilter('player','player');
4.电梯代码(@吉吉喵)
const elevator = world.querySelector('#电梯板-1') //获取电梯板实体
elevator.fixed = true //不可推移
elevator.collides = true //可碰撞
const pos = elevator.position//电梯板原本的位置
const ani = elevator.animate([
{ position: pos, duration: 1 },
{ position: pos, duration: 10 },
{ position: pos.add({ x: 0, y: 0, z: 15 }), duration: 1 },
{ position: pos.add({ x: 0, y: 0, z: 15 }), duration: 10 },
], {
duration: 15 * 16 , //播放一个循环共用时15秒(系统默认每秒16帧)
iterations: Infinity,
direction: Box3AnimationDirection.WRAP,//让动画实体从终点回到起点
})
注意:自行更改数据~
附:速建一层水~
for(let x=0; x<255; x++){
for(let z=0; z<255; z++){
voxels.setVoxel(x, 8, z, 'water')
}}
注意:1.可以用同样原理建围墙~
2.先放代码区测试,再移到控制台~